mirror of
https://github.com/discourse/discourse.git
synced 2024-12-04 21:23:44 +08:00
10 lines
370 B
JavaScript
10 lines
370 B
JavaScript
// stolen from http://stackoverflow.com/a/13484088/11983
|
|
export default (percentages) => {
|
|
const sumOfDecimals = Math.ceil(percentages.map(a => a % 1).reduce((a, b) => a + b));
|
|
// compensate error by adding 1 to the first n items
|
|
for (let i = 0; i < sumOfDecimals; i++) {
|
|
percentages[i] = ++percentages[i];
|
|
}
|
|
return percentages.map(a => Math.floor(a));
|
|
};
|