Created
January 15, 2016 20:09
-
-
Save cynthiaerdos/b0dfbbbf0b198228d759 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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