Skip to content

Instantly share code, notes, and snippets.

@victorpotasso
Created April 16, 2014 02:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorpotasso/10799487 to your computer and use it in GitHub Desktop.
Save victorpotasso/10799487 to your computer and use it in GitHub Desktop.
Create a multidimensional grid using just a loop with modulo
var rows = 4;
var cols = 5;
var total = rows * cols;
var i = 0;
while(i<total)
{
var posX = Math.floor(i/rows);
var posY = i % rows;
console.log("pos[" + posX + "][" + posY + "]");
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment