Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function foo(obj, max, value) {
  2.     const keys = Object.keys(obj);
  3.     const x = keys.map(key => Math.max(0, max - obj[key]))
  4.                   .reduce((a, b) => a + b, 0);
  5.  
  6.     const result = {};
  7.  
  8.     for (const key of keys) {
  9.         result[key] = value / x * Math.max(0, max - obj[key]);
  10.     }
  11.  
  12.     return result;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement