mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Coerce drop and dropRight n param using toInteger (#4412)
* Coerce dropRight n param using toInteger * Coerce drop n param using toInteger
This commit is contained in:
committed by
John-David Dalton
parent
a965836cf3
commit
37cd5dc97a
@@ -1,4 +1,5 @@
|
||||
import slice from './slice.js'
|
||||
import toInteger from './toInteger.js'
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` with `n` elements dropped from the end.
|
||||
@@ -24,7 +25,8 @@ import slice from './slice.js'
|
||||
*/
|
||||
function dropRight(array, n=1) {
|
||||
const length = array == null ? 0 : array.length
|
||||
return length ? slice(array, 0, n < 0 ? 0 : -n) : []
|
||||
n = length - toInteger(n)
|
||||
return length ? slice(array, 0, n < 0 ? 0 : n) : []
|
||||
}
|
||||
|
||||
export default dropRight
|
||||
|
||||
Reference in New Issue
Block a user