Empty jars to the back
Shelve the empty jars at the back without reshuffling the full ones.
Write moveZeroes(nums): return a new array with every 0 moved to the end, and every other number kept in its original order.
Call show(arr) each time you move something and the stage plays the shelf as bars.
Example: moveZeroes([0, 1, 0, 3, 12]) returns [1, 3, 12, 0, 0].
Tests you can see
moveZeroes([0,1,0,3,12])[1,3,12,0,0]moveZeroes([4,0,5])[4,5,0]
More tests are hidden. The server runs them all before a time counts.
Call show() while your code works and the run plays back here.
javascriptmoveZeroes()
Tab indents · Cmd/Ctrl+Enter runs