mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Remove baseSlice.
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* The base implementation of `slice`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to slice.
|
||||
* @param {number} [start=0] The start position.
|
||||
* @param {number} [end=array.length] The end position.
|
||||
* @returns {Array} Returns the slice of `array`.
|
||||
*/
|
||||
function baseSlice(array, start, end) {
|
||||
let index = -1
|
||||
let { length } = array
|
||||
|
||||
if (start < 0) {
|
||||
start = -start > length ? 0 : (length + start)
|
||||
}
|
||||
end = end > length ? length : end
|
||||
if (end < 0) {
|
||||
end += length
|
||||
}
|
||||
length = start > end ? 0 : ((end - start) >>> 0)
|
||||
start >>>= 0
|
||||
|
||||
const result = new Array(length)
|
||||
while (++index < length) {
|
||||
result[index] = array[index + start]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default baseSlice
|
||||
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './baseSlice.js'
|
||||
import slice from '../slice.js'
|
||||
|
||||
/**
|
||||
* The base implementation of methods like `dropWhile` and `takeWhile`.
|
||||
@@ -18,8 +18,8 @@ function baseWhile(array, predicate, isDrop, fromRight) {
|
||||
predicate(array[index], index, array)) {}
|
||||
|
||||
return isDrop
|
||||
? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
|
||||
: baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index))
|
||||
? slice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
|
||||
: slice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index))
|
||||
}
|
||||
|
||||
export default baseWhile
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './baseSlice.js'
|
||||
import slice from '../slice.js'
|
||||
|
||||
/**
|
||||
* Casts `array` to a slice if it's needed.
|
||||
@@ -12,7 +12,7 @@ import baseSlice from './baseSlice.js'
|
||||
function castSlice(array, start, end) {
|
||||
const { length } = array
|
||||
end = end === undefined ? length : end
|
||||
return (!start && end >= length) ? array : baseSlice(array, start, end)
|
||||
return (!start && end >= length) ? array : slice(array, start, end)
|
||||
}
|
||||
|
||||
export default castSlice
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import baseGet from './baseGet.js'
|
||||
import baseSlice from './baseSlice.js'
|
||||
import slice from '../slice.js'
|
||||
|
||||
/**
|
||||
* Gets the parent value at `path` of `object`.
|
||||
@@ -10,7 +10,7 @@ import baseSlice from './baseSlice.js'
|
||||
* @returns {*} Returns the parent value.
|
||||
*/
|
||||
function parent(object, path) {
|
||||
return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1))
|
||||
return path.length < 2 ? object : baseGet(object, slice(path, 0, -1))
|
||||
}
|
||||
|
||||
export default parent
|
||||
|
||||
4
chunk.js
4
chunk.js
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './.internal/baseSlice.js'
|
||||
import slice from './slice.js'
|
||||
|
||||
/**
|
||||
* Creates an array of elements split into groups the length of `size`.
|
||||
@@ -29,7 +29,7 @@ function chunk(array, size) {
|
||||
const result = new Array(Math.ceil(length / size))
|
||||
|
||||
while (index < length) {
|
||||
result[resIndex++] = baseSlice(array, index, (index += size))
|
||||
result[resIndex++] = slice(array, index, (index += size))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
4
drop.js
4
drop.js
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './.internal/baseSlice.js'
|
||||
import slice from './slice.js'
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` with `n` elements dropped from the beginning.
|
||||
@@ -25,7 +25,7 @@ import baseSlice from './.internal/baseSlice.js'
|
||||
function drop(array, n=1) {
|
||||
const length = array == null ? 0 : array.length
|
||||
return length
|
||||
? baseSlice(array, n < 0 ? 0 : n, length)
|
||||
? slice(array, n < 0 ? 0 : n, length)
|
||||
: []
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './.internal/baseSlice.js'
|
||||
import slice from './slice.js'
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` with `n` elements dropped from the end.
|
||||
@@ -28,7 +28,7 @@ function dropRight(array, n=1) {
|
||||
return []
|
||||
}
|
||||
n = length - n
|
||||
return baseSlice(array, 0, n < 0 ? 0 : n)
|
||||
return slice(array, 0, n < 0 ? 0 : n)
|
||||
}
|
||||
|
||||
export default dropRight
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './.internal/baseSlice.js'
|
||||
import slice from './slice.js'
|
||||
|
||||
/**
|
||||
* Gets all but the last element of `array`.
|
||||
@@ -14,7 +14,7 @@ import baseSlice from './.internal/baseSlice.js'
|
||||
*/
|
||||
function initial(array) {
|
||||
const length = array == null ? 0 : array.length
|
||||
return length ? baseSlice(array, 0, -1) : []
|
||||
return length ? slice(array, 0, -1) : []
|
||||
}
|
||||
|
||||
export default initial
|
||||
|
||||
22
slice.js
22
slice.js
@@ -1,5 +1,3 @@
|
||||
import baseSlice from './.internal/baseSlice.js'
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` from `start` up to, but not including, `end`.
|
||||
*
|
||||
@@ -15,13 +13,29 @@ import baseSlice from './.internal/baseSlice.js'
|
||||
* @returns {Array} Returns the slice of `array`.
|
||||
*/
|
||||
function slice(array, start, end) {
|
||||
const length = array == null ? 0 : array.length
|
||||
let length = array == null ? 0 : array.length
|
||||
if (!length) {
|
||||
return []
|
||||
}
|
||||
start = start == null ? 0 : start
|
||||
end = end === undefined ? length : end
|
||||
return baseSlice(array, start, end)
|
||||
|
||||
if (start < 0) {
|
||||
start = -start > length ? 0 : (length + start)
|
||||
}
|
||||
end = end > length ? length : end
|
||||
if (end < 0) {
|
||||
end += length
|
||||
}
|
||||
length = start > end ? 0 : ((end - start) >>> 0)
|
||||
start >>>= 0
|
||||
|
||||
let index = -1
|
||||
const result = new Array(length)
|
||||
while (++index < length) {
|
||||
result[index] = array[index + start]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default slice
|
||||
|
||||
4
take.js
4
take.js
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './.internal/baseSlice.js'
|
||||
import slice from './slice.js'
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` with `n` elements taken from the beginning.
|
||||
@@ -26,7 +26,7 @@ function take(array, n=1) {
|
||||
if (!(array != null && array.length)) {
|
||||
return []
|
||||
}
|
||||
return baseSlice(array, 0, n < 0 ? 0 : n)
|
||||
return slice(array, 0, n < 0 ? 0 : n)
|
||||
}
|
||||
|
||||
export default take
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import baseSlice from './.internal/baseSlice.js'
|
||||
import slice from './slice.js'
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` with `n` elements taken from the end.
|
||||
@@ -28,7 +28,7 @@ function takeRight(array, n=1) {
|
||||
return []
|
||||
}
|
||||
n = length - n
|
||||
return baseSlice(array, n < 0 ? 0 : n, length)
|
||||
return slice(array, n < 0 ? 0 : n, length)
|
||||
}
|
||||
|
||||
export default takeRight
|
||||
|
||||
Reference in New Issue
Block a user