didkoslawow

Untitled

Jan 20th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. function wallBuilding(startingHeight) {
  2. let startingHeightParsed = startingHeight.map(Number);
  3. const concretePerCicle = 195;
  4. const concretePricePerCubicYard = 1900;
  5. let printResult = [];
  6.  
  7. const moneyNeeded = function (initialHeight) {
  8. let concreteUsed = 0;
  9.  
  10. for (let i = initialHeight; i < 30; i++) {
  11. concreteUsed += concretePerCicle;
  12. }
  13.  
  14. return concreteUsed;
  15. };
  16.  
  17. let startingHeightLength = startingHeightParsed.length;
  18. let totalConcreteUsed = 0;
  19. let crews = startingHeightParsed.filter((len) => len < 30).length;
  20.  
  21. for (let i = 0; i < startingHeightLength; i++) {
  22. totalConcreteUsed += moneyNeeded(startingHeightParsed[i]);
  23. }
  24.  
  25. while (crews !== 0) {
  26. let concretePerDay = 0;
  27. for (let j = 0; j < startingHeightLength; j++) {
  28. if (startingHeightParsed[j] !== 30) {
  29. startingHeightParsed[j]++;
  30. concretePerDay += concretePerCicle;
  31. if (startingHeightParsed[j] === 30) {
  32. crews--;
  33. }
  34. }
  35. }
  36. printResult.push(concretePerDay);
  37. }
  38.  
  39. let totalCosts = totalConcreteUsed * concretePricePerCubicYard;
  40.  
  41. console.log(printResult.join(', '));
  42. console.log(totalCosts + ' pesos');
  43. }
Advertisement
Add Comment
Please, Sign In to add comment