The Zero Migrator

MediumAcc. 89.4%
+30 XP 12

Resource Compaction

In memory management, we often move "empty" slots (zeros) to the end of a block.

The Assignment

Your function receives an array data.

  1. Iterate through the array and print all non-zero numbers first.
  2. Count how many zeros were in the array.
  3. Print that many zeros afterward.
  4. Each number should be on a new line.

01EXAMPLE 1

Input[0, 1, 0, 3, 12]
Output1 3 12 0 0

Explanation: Non-zeros first, then trailing zeros.

Constraints

  • Relative order of non-zeros must be preserved.
ArraysLoops
JavaScript
Loading...
1 Hidden

Input Arguments

data[0,1,0,3,12]

Expected Output

1
3
12
0
0

Click RUN to test your solution