Skip to content

Instantly share code, notes, and snippets.

@cynthiaerdos
Created January 15, 2016 20:09
Show Gist options
  • Save cynthiaerdos/b0dfbbbf0b198228d759 to your computer and use it in GitHub Desktop.
Save cynthiaerdos/b0dfbbbf0b198228d759 to your computer and use it in GitHub Desktop.
console.log(getGraph(20));
function getGraph(stepNumber) {
var array = [];
for (var i = 0; i < stepNumber + 1; i++) {
array.push(getCoordinate(i));
}
function getCoordinate(step) {
var stepCalc = step % 4;
if (!stepCalc) {
return [-1 * (step / 4), -1 * (step / 4)];
} else if (!(stepCalc - 1)) {
return [-1 * Math.floor(step / 4), Math.floor(step / 4) + 1];
} else if (!(stepCalc - 2)) {
return [Math.floor(step / 4) + 1, Math.floor(step / 4) + 1];
} else if (!(stepCalc - 3)) {
return [Math.floor(step / 4) + 1, -1 * (Math.floor(step / 4) + 1)];
}
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment