Array.prototype.popbeginnerconst stack = [1, 2, 3]
const top = stack.pop() // β 3
stack // β [1, 2]Use pop() to remove and return the last element of an array.
Array.prototype.pop() removes the last element from an array and returns it. The array is mutated in place (its length decreases by 1).
Challenge: Implement removeLast(arr) that pops and returns the removed element.
removeLast([1, 2, 3]) // β 3 (arr is now [1, 2])
removeLast([42]) // β 42 (arr is now [])