Array.prototype.withbeginnerconst arr = [1, 2, 3, 4]
arr.with(1, 99) // β [1, 99, 3, 4]
arr // β [1, 2, 3, 4] (unchanged)Use with(index, value) to return a new array with one element replaced, leaving the original intact.
The with() method returns a new array with the element at the given index replaced by the provided value.
Implement replaceAt that returns arr.with(index, val).