mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-03 04:17:34 -05:00
9 lines
353 B
Text
9 lines
353 B
Text
|
// stolen from http://stackoverflow.com/a/13485888/11983
|
||
|
export default (percentages) => {
|
||
|
const off = 100 - _.reduce(percentages, (acc, x) => acc + Math.round(x), 0);
|
||
|
return _.chain(percentages)
|
||
|
.sortBy(x => Math.round(x) - x)
|
||
|
.map((x, i) => Math.round(x) + (off > i) - (i >= (percentages.length + off)))
|
||
|
.value();
|
||
|
};
|