-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpract0620.js
More file actions
49 lines (43 loc) · 763 Bytes
/
pract0620.js
File metadata and controls
49 lines (43 loc) · 763 Bytes
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
42
43
44
45
46
47
48
49
let array = [0, 0, 0];
const stepOne = () => {
console.log(array);
let count = 0;
for (let i = 0; i < array.length; i++) {
if (array[i] === 0) {
array[i] = 1;
}
if (i > 0) {
array[count] = 0;
count++;
}
console.log(array);
}
array[count] = 0;
console.log(array);
};
// stepOne(array);
const step = () => {
let count = 0;
for (let i = 0; i < array.length; i++) {
if (array[i] === 0) {
array[i] = 1;
return array;
}
if (i > 0) {
array[count] = 0;
count++;
}
}
array[count] = 0;
};
const walk = (array, n) => {
console.log(array);
let move = 0;
while (move < n) {
step();
console.log(array);
move++;
}
return [array, n];
};
walk(array, 3);