仅做记录之用
function randomAllocation(total, n) {
// TODO: 待补充代码
let res = [];
let val = 0;
let money = total;
for (let i = 0; i < n - 1; i++) {
val = +(Math.random() * (money - (n - i - 1) * 0.01 - 0.01) + 0.01).toFixed(2); //toFixed此处返回字符串,+号是是结果返回为number?
//先-0.01再+0.01是为了保证最少能得0.01
money -= val;
res.push(val);
}
res.push(+(money).toFixed(2));
console.log(res);
return res;
}