Advertisement
EntropyStarRover

10. Build a wall*

Jun 15th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wall(sections){
  2.  
  3.     let stone=0;
  4.     let days=[];
  5.  
  6. function finishSection(section){
  7.     let day=0;
  8.     while (section<30){
  9.         section++;
  10.       day++;  
  11.     }
  12.     days.push(day);
  13.     return section;
  14. }
  15.  
  16. for (let i=0;i<sections.length; i++){
  17.     finishSection(sections[i]);
  18. }
  19.  
  20. let totalStone=0;
  21. let dailyStones=[];
  22.  
  23. while (Math.max(...days)>0){
  24.     let daySum=0;
  25.     for (let j=0; j<days.length; j++ ){
  26.         if (days[j]>0){
  27.             daySum+=195;
  28.            
  29.         }      
  30.            }
  31.  
  32.     dailyStones.push(daySum);
  33.  
  34.     totalStone+=daySum;
  35.     days=days.map(day=>day-1);
  36.    
  37. }
  38.         console.log(dailyStones.join(", "));
  39.      console.log(`${totalStone*1900} pesos`);    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement