Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Created September 20, 2012 18:43
Show Gist options
  • Select an option

  • Save michaelminter/3757605 to your computer and use it in GitHub Desktop.

Select an option

Save michaelminter/3757605 to your computer and use it in GitHub Desktop.
Take an array and move all zeros to front
array, newarray = [0, 3, 0, 6, 0, 4], []
array.each { |a|
a == 0 ? newarray.unshift(a) : newarray << a
}
puts newarray.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment