in reply to move all 0s in an array to the beginning keeping other elements order same

My first instinct there would be to:

  1. use grep to filter all zeros from the array;
  2. count them while you're doing that, and then prepend a suitable number of zeros to the filtered array.

I don't know whether that's a particularly efficient solution.

  • Comment on Re: move all 0s in an array to the beginning keeping other elements order same