Skip to content

Instantly share code, notes, and snippets.

@aconfee
Created October 12, 2016 17:15
Show Gist options
  • Save aconfee/8535e65565c606c5ab1ee3947a15d91a to your computer and use it in GitHub Desktop.
Save aconfee/8535e65565c606c5ab1ee3947a15d91a to your computer and use it in GitHub Desktop.
private sortedItemsToBalancedColumns(orderedValues: any, numberOfColumns: number): any[] {
var numberOfValues = orderedValues.length;
var numberOfCompleteRows = Math.floor(numberOfValues / numberOfColumns);
var lengthOfExtraRow = numberOfValues % numberOfColumns;
var columns = new Array(numberOfColumns);
for (let i = 0; i < numberOfColumns; i++) {
if (lengthOfExtraRow > 0) {
columns[i] = orderedValues.splice(0, numberOfCompleteRows + 1);
lengthOfExtraRow--;
} else {
columns[i] = orderedValues.splice(0, numberOfCompleteRows);
}
}
return columns;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment