Skip to content

Commit

Permalink
Add JavaScript::5 kyu::Moving Zeros To The End
Browse files Browse the repository at this point in the history
  • Loading branch information
Toggoren committed May 1, 2022
1 parent afbd783 commit e65a376
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,6 @@
[``go to description``](https://www.codewars.com/kata/57b6f5aadb5b3d0ae3000611) [``go to solution``](javascript/kyu_6/length-of-missing-array.js)
* rank: ````6 kyu```` language: ``JavaScript`` task name: ``Easter egg list in ReactJS``
[``go to description``](https://www.codewars.com/kata/5a95947f4a6b342636000173) [``go to solution``](javascript/kyu_6/easter-egg-list-in-reactjs.js)
* rank: ````5 kyu```` language: ``JavaScript`` task name: ``Moving Zeros To The End``
[``go to description``](https://www.codewars.com/kata/52597aa56021e91c93000cb0) [``go to solution``](javascript/kyu_5/moving-zeros-to-the-end.js)

20 changes: 20 additions & 0 deletions javascript/kyu_5/moving-zeros-to-the-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
https://www.codewars.com/kata/52597aa56021e91c93000cb0/train/javascript
*/

const moveZeros = (arr) => {
let movesCounter = 0
let i = 0
while (i < arr.length) {
if (i + movesCounter > arr.length) {
break
}
if (arr[i] === 0) {
arr.push(arr.splice(i, 1)[0])
movesCounter = movesCounter + 1
continue
}
i = i + 1
}
return arr
}

0 comments on commit e65a376

Please # to comment.