const params = {
2: {
bronze: 0.547,
},
3: {
bronze: 0.522,
silver: 0.076,
},
4: {
bronze: 0.48,
silver: 0.042,
gold: 0.077,
},
6: {
bronze: 0.461,
silver: 0.092,
gold: 0.051,
rainbow: 0.028,
},
};
const shaping = (value, base) => Math.round(value * base) / base;
const result = Object.keys(params).reduce((acc, settei) => {
const start = 1000;
const end = 7000;
const target = params[settei];
acc[settei] = {};
const keys = Object.keys(params[settei]);
keys.map(key => {
acc[settei][key] = {};
for (let i = start; i <= end; i += 1000) {
acc[settei][key][i] = shaping(
1 - ((1 - target[key]) ** (1 / 2000)) ** i,
1000
);
}
});
if (keys.length === 1) {
return acc;
}
const sum = keys.reduce((acc, k) => {
acc += target[k];
return acc;
}, 0);
acc[settei]['sum'] = {};
for (let i = start; i <= end; i += 1000) {
acc[settei]['sum'][i] = shaping(1 - ((1 - sum) ** (1 / 2000)) ** i, 1000);
}
return acc;
}, {});
console.log(result);