Advertisement
kstoyanov

01. Bitcoin Mining js exam

Aug 5th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const bitcoin = 11949.16;
  3.   const gold = 67.51;
  4.   let totalSum = 0;
  5.   let day = 0;
  6.   let firstDay = 0;
  7.   let boughtBitcoin = 0;
  8.   let countBitcoin = 0;
  9.   let sumBitcoins = 0;
  10.  
  11.  
  12.   args.forEach((element) => {
  13.     day++;
  14.     if (day % 3 === 0) {
  15.       element *= 0.7;
  16.     }
  17.  
  18.     const singleDayEarning = element * gold;
  19.     totalSum += singleDayEarning;
  20.  
  21.  
  22.     if (totalSum >= bitcoin) {
  23.       countBitcoin++;
  24.       boughtBitcoin = Math.floor(totalSum / bitcoin);
  25.       totalSum -= (bitcoin * boughtBitcoin);
  26.       sumBitcoins += boughtBitcoin;
  27.     }
  28.     if (countBitcoin === 1) {
  29.       firstDay = day;
  30.     }
  31.   });
  32.  
  33.   console.log(`Bought bitcoins: ${sumBitcoins}`);
  34.   if (firstDay !== 0) {
  35.     console.log(`Day of the first purchased bitcoin: ${firstDay}`);
  36.   }
  37.   console.log(`Left money: ${totalSum.toFixed(2)} lv.`);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement