Skip to content

Files

Latest commit

author
Travis CI
Dec 28, 2017
3cbd704 · Dec 28, 2017

History

History
15 lines (11 loc) · 336 Bytes

dropRight.md

File metadata and controls

15 lines (11 loc) · 336 Bytes

dropRight

Returns a new array with n elements removed from the right.

Use Array.slice() to slice the remove the specified number of elements from the right.

const dropRight = (arr, n = 1) => arr.slice(0, -n);
dropRight([1, 2, 3]); // [1,2]
dropRight([1, 2, 3], 2); // [1]
dropRight([1, 2, 3], 42); // []