Todorov_Stanimir

10. Build a Wall Arrays Advanced - Exercise

Jun 12th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function buildAWall(input) {
  2.     input = input.map(Number);
  3.     let output = [];
  4.     let counterDifference = [];
  5.     let maxDifference = 0;
  6.     let pesos=0;
  7.  
  8.     for (let i = 0; i < input.length; i++) {
  9.         counterDifference.push(30 - input[i]);
  10.         if (maxDifference < (30 - input[i])) {
  11.             maxDifference=30-input[i];
  12.         }
  13.     }
  14.     for (let y = 0; y <= maxDifference; y++) {
  15.         let counterMilesPerDay = 0;
  16.         for (let i = 0; i < counterDifference.length; i++) {
  17.             if (counterDifference[i] > 0) {
  18.                 counterDifference[i]--;
  19.                 counterMilesPerDay++;
  20.             }
  21.         }
  22.         if (counterMilesPerDay!==0) {
  23.             output.push(counterMilesPerDay * 195);
  24.             pesos += 1900 * output[y];
  25.         }
  26.     }
  27.     console.log(output.join(', '));
  28.     console.log(`${pesos} pesos`);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment