Skip to content

Instantly share code, notes, and snippets.

@noeldelgado
Created April 17, 2013 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noeldelgado/5405571 to your computer and use it in GitHub Desktop.
Save noeldelgado/5405571 to your computer and use it in GitHub Desktop.
Calculate the exact number of rows and columns for N number of items
var N = 216, // total number of items
rows = Math.floor( Math.sqrt( N ) ),
columns = 0;
while ( N % rows != 0 ) {
rows = rows - 1;
}
columns = N / rows;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment