mrdeeds88

Donator Fantasy formular

Aug 21st, 2021 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let players = [
  2.     {
  3.       id: 1,
  4.       point: 100
  5.     },
  6.     {
  7.       id: 2,
  8.       point: 88
  9.     },
  10.     {
  11.       id: 3,
  12.       point: 22
  13.     },
  14.     {
  15.       id: 4,
  16.       point: 80
  17.     },
  18.     {
  19.       id: 5,
  20.       point: 66
  21.     },
  22.     {
  23.       id: 6,
  24.       point: 88
  25.     },
  26.     {
  27.       id: 7,
  28.       point: 58
  29.     },
  30.     {
  31.       id: 8,
  32.       point: 58
  33.     },
  34.     {
  35.       id: 9,
  36.       point: 58
  37.     },
  38.     {
  39.       id: 10,
  40.       point: 60
  41.     },
  42.     {
  43.       id: 11,
  44.       point: 70
  45.     },
  46.     {
  47.       id: 12,
  48.       point: 80
  49.     }
  50.   ]
  51.  
  52. /****************************** Start here ******************************/
  53.   let sortedPlayers = [...players].sort((a, b) => a.point - b.point)
  54.  
  55.  
  56.   const moneyByPoint = {}
  57.   const maxMoney = 70000
  58.   const step = 10000
  59.  
  60.   for (let index = 0; index < sortedPlayers.length; index++) {
  61.     const player = sortedPlayers[index]
  62.  
  63.     if(!moneyByPoint[player.point]) {
  64.       let money = maxMoney - index * step
  65.  
  66.       moneyByPoint[player.point] = {
  67.         count: 1,
  68.         money: money > 0 ? money : 0,
  69.       }
  70.     } else {
  71.       let currentMoney = (maxMoney - index * step)
  72.       let count = moneyByPoint[player.point].count + 1
  73.       let money = ((currentMoney + (count - 1) * step) + currentMoney)/2//(first + end) / 2\
  74.  
  75.       moneyByPoint[player.point] = {
  76.         count: count,
  77.         money: money > 0 ? money : 0
  78.       }
  79.     }
  80.   }
  81.  
  82.   console.log(moneyByPoint)
Add Comment
Please, Sign In to add comment