Array.prototype.sliceintermediateconst arr = [1, 2, 3, 4, 5]
arr.slice(-2) // β [4, 5] (last 2 elements)Use a negative argument with slice() to extract elements counting from the end.
When a negative index is passed to slice(), it counts from the end of the array. arr.slice(-n) returns the last n elements.
Challenge: Implement lastN(arr, n) that returns the last n elements using arr.slice(-n).
lastN([1, 2, 3, 4, 5], 2) // β [4, 5]
lastN([10, 20, 30], 1) // β [30]