Skip to content

Instantly share code, notes, and snippets.

@Gabri3l
Created August 14, 2016 00:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gabri3l/3c38b5db7513e0db0736b1e3c9dff565 to your computer and use it in GitHub Desktop.
Save Gabri3l/3c38b5db7513e0db0736b1e3c9dff565 to your computer and use it in GitHub Desktop.
var spiralize = function(size) {
let spiral = [];
for(let i=0;i<size;i++) {
spiral[i] = Array(size).fill(0);
}
let min = 0;
let max = size;
while (min < max ) {
for(let i=min;i<max;i++) {
spiral[min][i] = 1; //first row
spiral[i][max-1] = 1; //last col
if (max - min > 2) spiral[max-1][i] = 1; //last row
if (i>=min+2) spiral[i][min] = 1; //first col
if (i===min+2) spiral[i][min+1] = 1; //curl
}
min += 2;
max -= 2;
}
return spiral
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment