function put0AtTheBack(arr) { let zeroIndex = -1; for(let i = 0; i < arr.length; i++) { let item = arr[i]; if(item !== '0' && item !== 0 && zeroIndex !== -1) { let tmp = arr[i]; arr[i] = arr[zeroIndex]; arr[zeroIndex] = tmp; zeroIndex++; } if((item === '0' || item === 0) && zeroIndex === -1) { zeroIndex = i; } } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: JavaScript Challenge 3: Remove Zeroes
Replies for: OK, you beat me this time! :D You're about 3x faster Swapping the toString()s for two comparisons speeds it up a bit, but it still takes more than...
For further actions, you may consider blocking this person and/or reporting abuse