Skip to content

Instantly share code, notes, and snippets.

@pketh
Last active August 17, 2020 12:18
Show Gist options
  • Save pketh/dda5042767871b0a311729ccabeda01d to your computer and use it in GitHub Desktop.
Save pketh/dda5042767871b0a311729ccabeda01d to your computer and use it in GitHub Desktop.
moveZeros([1, 2, 0, 1, 0, 0, 3, 6])
const moveZeroes = (numbers) => {
let zeroes = []
numbers = numbers.filter(number => {
if (number === 0) {
zeroes.push(number)
} else {
return true
}
})
zeroes.forEach(zero => numbers.push(zero))
// numbers = [1, 2, 1, 3, 6, 0, 0, 0]
return numbers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment