mihalkoff

Build a wall

Mar 10th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function buildWall(arr) {
  2. arr = arr.map(Number);
  3.  
  4. let wallSections = arr.length;
  5.  
  6. let workingDays = 30 - Math.min(...arr);
  7. let concrete = [];
  8.  
  9. for(let i = 0; i < workingDays; i++) {
  10. if(arr.includes(30)) {
  11. arr.splice(arr.indexOf(30), 1);
  12. wallSections = arr.length;
  13. }
  14.  
  15. concrete.push(wallSections * 195);
  16. arr = arr.map(x => x + 1);
  17. }
  18.  
  19. let totalConcrete = 0;
  20.  
  21. for(let el of concrete) {
  22. totalConcrete += el;
  23. }
  24.  
  25. console.log(concrete.join(', '));
  26. console.log(`${totalConcrete * 1900} pesos`);
  27. }
  28.  
  29. buildWall([17, 22, 17, 19, 17]);
Advertisement
Add Comment
Please, Sign In to add comment