Remove baseSlice.

This commit is contained in:
John-David Dalton
2017-04-17 21:03:39 -07:00
parent a023f92049
commit e5e8f35c06
11 changed files with 37 additions and 54 deletions

View File

@@ -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