Mark As Completed Discussion

We can do better.

The above snippet would get the job done, but requires extra space with the new temp array.

Without a temp array, we'll need to change the position of elements in the array in-place. This means that we'll need to mutate the array's elements directly. This requires us to keep track of indexes.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment