Skip to content

Instantly share code, notes, and snippets.

@benaston
Created March 6, 2014 09:51
Show Gist options
  • Save benaston/9386374 to your computer and use it in GitHub Desktop.
Save benaston/9386374 to your computer and use it in GitHub Desktop.
Random JavaScript
var countries = [ "A", "B", "C", "D", "E", "F", "G", "H", "I" ]
var grouped = [];
var count = countries.length;
var columns = 4;
var rows = Math.floor(count/columns);
countries.map(function(c,i,a){
return { key: i%rows, value: c };
}).forEach(function(kvp) {
grouped[kvp.key] = grouped[kvp.key] || [];
grouped[kvp.key].push(kvp.value);
});
var result = grouped.reduce(function(prev, curr, index, arr){
return prev.concat(curr);
}, []);
var counter = 1;
var bestFitColumns =
result.forEach(function(i) {
console.log('%s ', i);
if(counter%columns === 0) {
//console.log('\n');
}
counter++;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment