Update drop-right.md

shorter comparison of `n` and `arr.length`
This commit is contained in:
taltmann42
2017-12-18 19:15:51 +01:00
committed by GitHub
parent 70ec53e2f0
commit ae7732cd3e

View File

@ -5,7 +5,7 @@ Returns a new array with `n` elements removed from the right
Checks if `n` is shorter than the given array and slices it accordingly or returns an empty array Checks if `n` is shorter than the given array and slices it accordingly or returns an empty array
```js ```js
const dropRight = (arr, n = 1) => (arr.length - n ) > 0 ? arr.slice(0, arr.length - n) : [] const (arr, n = 1) => n < arr.length ? arr.slice(0, arr.length - 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]