-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveZeros.js
41 lines (32 loc) · 968 Bytes
/
moveZeros.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function moveZeros(array) {
let totalSum = 0
// for (let ele of array) {
// console.log('ele', ele)
// if (ele === 0) {
// totalSum++
// array[array.length-1] = array[i]
// }
// }
for (let i = 0; i < array.length; i++) {
if (array[i] === 0) {
// array[array.length - 1] = array[i]
totalSum++
} else {
// array[i] = array[i]
console.log('))))))',array[i])
}
}
console.log('totalSum', totalSum)
console.log('array', array)
// for (let i = 0; i < array.length; i++) {
// if (array[i] === 0) {
// // console.log('first', i, '===', array)
// array.splice(i, 1)
// array.push(0)
// console.log('newArr', i, array)
// }
// }
// console.log(array)
}
// moveZeros([0, 1, 0, 3, 12])
moveZeros([0, 0, 1])