Last active
July 19, 2021 16:38
-
-
Save danielistyo/97d77a53781fd99577b5bd103b74aed3 to your computer and use it in GitHub Desktop.
Revisions
-
danielistyo revised this gist
Jul 19, 2021 . 1 changed file with 15 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ function generateTornado(w, h) { let x = 0, y = 0, direction = 'right', newTornado = Array.from(tornado, t => [...t]), count = 1; do { @@ -27,17 +27,22 @@ function generateTornado(w, h) { tornado[x][y] = count; x++; } direction = 'left'; y--; x--; count++; if (!tornado[x][y]) { newTornado = Array.from(newTornado, t => { const arr = []; for (let k = 0; k < t.length - 1; k++) { arr.push(t[k]); } return arr; }); } else { break; } } else if (direction === 'left') { for (let j = 0; j < newTornado[0].length; j++) { tornado[x][y] = count; @@ -58,7 +63,7 @@ function generateTornado(w, h) { x++; count++; if (!tornado[x][y]) { newTornado = Array.from(newTornado, t => { const arr = []; for (let k = 1; k < t.length; k++) { arr.push(t[k]); @@ -75,4 +80,4 @@ function generateTornado(w, h) { console.log(tornado[t].join(' ')); } } generateTornado(7, 10); -
danielistyo revised this gist
Dec 11, 2020 . No changes.There are no files selected for viewing
-
danielistyo revised this gist
Dec 11, 2020 . No changes.There are no files selected for viewing
-
danielistyo revised this gist
Dec 11, 2020 . No changes.There are no files selected for viewing
-
danielistyo revised this gist
Dec 11, 2020 . No changes.There are no files selected for viewing
-
danielistyo revised this gist
Dec 11, 2020 . No changes.There are no files selected for viewing
-
danielistyo renamed this gist
Dec 11, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
danielistyo created this gist
Dec 11, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ function generateTornado(w, h) { // initiate tornado const tornado = new Array(h); for (let i = 0; i < tornado.length; i++) { tornado[i] = new Array(w); } let x = 0, y = 0, direction = 'right', newTornado = Array.from(tornado, (t) => [...t]), count = 1; do { if (direction === 'right') { for (let j = 0; j < newTornado[0].length; j++) { tornado[x][y] = count; y++; } newTornado.splice(0, 1); direction = 'down'; x++; y--; count++; } else if (direction === 'down') { for (let j = 0; j < newTornado.length; j++) { tornado[x][y] = count; x++; } newTornado = Array.from(newTornado, (t) => { const arr = []; for (let k = 0; k < t.length - 1; k++) { arr.push(t[k]); } return arr; }); direction = 'left'; y--; x--; count++; } else if (direction === 'left') { for (let j = 0; j < newTornado[0].length; j++) { tornado[x][y] = count; y--; } newTornado.splice(newTornado.length - 1, 1); direction = 'up'; x--; y++; count++; } else if (direction === 'up') { for (let j = 0; j < newTornado.length; j++) { tornado[x][y] = count; x--; } direction = 'right'; y++; x++; count++; if (!tornado[x][y]) { newTornado = Array.from(newTornado, (t) => { const arr = []; for (let k = 1; k < t.length; k++) { arr.push(t[k]); } return arr; }); } else { break; } } } while (newTornado.length); for (const t in tornado) { console.log(tornado[t].join(' ')); } } generateTornado(7, 8);