Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function foo(obj, max, value) {
- const keys = Object.keys(obj);
- const x = keys.map(key => Math.max(0, max - obj[key]))
- .reduce((a, b) => a + b, 0);
- const result = {};
- for (const key of keys) {
- result[key] = value / x * Math.max(0, max - obj[key]);
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement