Last active
June 23, 2017 08:38
-
-
Save trickpattyFH20/52736493ab6036e6574670a47ed514f0 to your computer and use it in GitHub Desktop.
splice zeros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [0, 0, 1, 0, 2, 3, 0, 4, 0, 5]; | |
var idx; | |
function findIdx() { | |
idx = a.indexOf(0); | |
return idx; | |
} | |
while (findIdx() !== -1) { | |
a.splice(idx, 1); | |
} | |
console.log(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment