Write Your Own Splice
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
Write mySplice(items, start, deleteCount, ...newItems) without using the built-in splice or toSpliced. Like the built-in, it changes items in place: it removes deleteCount items starting at position start, puts newItems in their place, and returns a new array of the removed items. A negative start counts back from the end, and a start beyond either end is moved to that end. When deleteCount is left out, everything from start to the end is removed. A negative deleteCount counts as 0, and one larger than what's left removes only what's left. The arrays in the checks have no gaps.
Your code must pass
- Removes items from start and returns them
- Puts the new items in their place
- Counts a negative start back from the end and clamps one out of range
- Removes to the end when deleteCount is left out, and clamps it
- Works without the built-in splice