-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameoflife.js
More file actions
52 lines (44 loc) · 981 Bytes
/
gameoflife.js
File metadata and controls
52 lines (44 loc) · 981 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
50
51
52
const generate2d = (n, m) => {
let arr = new Array(n);
for (let i = 0; i < n; i++) {
arr[i] = new Array(m);
}
return arr;
};
const fill2d = () => {
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array[i].length; j++) {
array[i][j] = 0;
}
}
};
const print2d = () => {
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array[i].length; j++) {
process.stdout.write(array[i][j] + ' ');
}
console.log();
}
};
const addCell = (arr, str) => {
let split = [];
split = str.split(' ');
let x = split[1];
let y = split[0];
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array[i].length; j++) {
if (Number(y) === i && Number(x) === j) {
array[i][j] = 1;
}
}
}
return [x, y];
};
const getNeighbors = (arr, x, y) => {
};
let str = '1 2';
let array = generate2d(5, 5);
fill2d();
addCell(array, str);
print2d(array);
let coordinates = addCell(array, str);