Update dropRight.md

This commit is contained in:
Angelos Chalaris
2017-12-24 14:11:30 +02:00
committed by GitHub
parent c816ce85ce
commit b1adedfbea

View File

@ -1,11 +1,11 @@
### dropRight ### dropRight
Returns a new array with `n` elements removed from the right 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. Use `Array.slice()` to slice the remove the specified number of elements from the right.
```js ```js
const dropRight = (arr, n = 1) => arr.slice(0, -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) -> []