JS Built-ins
← Array219 / 226
ArrayArray.prototype.withintermediate

Verify No Mutation

πŸ“– Usage Example
const original = [1, 2, 3]
const updated = original.with(0, 99)
original  // β†’ [1, 2, 3]  (unchanged)
updated   // β†’ [99, 2, 3]

with() never mutates the source array β€” it always returns a new array with the change applied.

Array.prototype.with β€” Immutability

with() does not mutate the original array. It always returns a new array.

Implement withNoMutation that calls arr.with(0, 99) but returns the original arr. The original should be unchanged.

πŸ’‘ Hints (2)
  • β€’ `with()` is a non-mutating method β€” calling it does not change the original array.
  • β€’ The return value of `arr.with(0, 99)` is a new array, not `arr`.