Push zeroes last

Write a javascript program that will push zeroes last. This is one of the question I was asked when I applied for my first job as a programmer. This is a little tricky for beginners

Push zeroes last : Requirement

Here are the requirements :

  • Accept numeric input from the user which should be more than 4-5 digits
  • You can take input using a prompt box or an input field
  • Push all the zeroes found in the input to end. For eg. if the input is “302005”. The output should be 325000

Push zeroes last : Hints

You will make use of the following javascript concepts:

  • Prompt box or input field
  • If/else/else-if
  • Arrays
  • For loop, For each
  • Concatenate arrays

Push zeroes last : Planning the logic

You will need to perform the following tasks

  • Get the input from the user
  • Store the values in variables
  • Split and convert it into array
  • Run a for loop to check for zeroes and non-zero number
  • Store the values in arrays
  • Concatenate and display the output

Find this challenging? Give it a spin.

Trying solving this using any of the online editors and send me an email if you need any help or feedback on your code.