-
-
Save benaston/9386374 to your computer and use it in GitHub Desktop.
Random JavaScript
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
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