Created
October 18, 2024 04:56
-
-
Save GabrielModog/c3525b71ab6d589af7994990c10d1e3d to your computer and use it in GitHub Desktop.
Revisions
-
GabrielModog created this gist
Oct 18, 2024 .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,15 @@ function spiralize(n) { return Array(n).fill(Array(n).fill(0)).map((i, row) => i.map((j, col) => { const north = row < n / 2 && row % 2 === 0 && col >= row - 1 && col <= n - row - 1 const east = (n-col) % 2 === 1 && row <= col && row > n - col - 1 const south = (n-row) % 2 === 1 && col < row && col > n - row - 1 const west = col % 2 === 0 && row < n - col && row > col + 1 const result = north || east || south || west return Number(result) })) } /** * Number(result) * false and true in JS can be read as 0 or 1 * so the class Number can turn boolean values into valid a number */