Bad example👎

The slice function can take the negative negative value of the second agrimement
This commit is contained in:
David Narbutovich
2017-12-23 14:00:04 +03:00
committed by GitHub
parent 2446be2556
commit 83fb2c523a

View File

@ -5,7 +5,7 @@ Returns a new array with `n` elements removed from the right
Check if `n` is shorter than the given array and use `Array.slice()` to slice it accordingly or return an empty array. Check if `n` is shorter than the given array and use `Array.slice()` to slice it accordingly or return an empty array.
```js ```js
const dropRight = (arr, n = 1) => n < arr.length ? arr.slice(0, arr.length - n) : [] const dropRight = (arr, n = 1) => arr.slice(0, -n)
//dropRight([1,2,3]) -> [1,2] //dropRight([1,2,3]) -> [1,2]
//dropRight([1,2,3], 2) -> [1] //dropRight([1,2,3], 2) -> [1]
//dropRight([1,2,3], 42) -> [] //dropRight([1,2,3], 42) -> []