nikolayneykov

Untitled

Mar 3rd, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printDeliveries(params) {
  2.     params.pop();
  3.     let houses = params.shift().split('@').map(Number);
  4.     let santaIndex = 0;
  5.  
  6.     for (let param of params) {
  7.         let jumpLength = Number(param.split(' ')[1]);
  8.         santaIndex = (santaIndex + jumpLength) % houses.length;
  9.  
  10.         if (houses[santaIndex] <= 0) {
  11.             console.log(`House ${santaIndex} will have a Merry Christmas.`);
  12.         }
  13.         houses[santaIndex] -= 2;
  14.     }
  15.     console.log(`Santa's last position was ${santaIndex}.`);
  16.    let failedHouses = 0;
  17.    for (let house of houses) {
  18.        if (house > 0) {
  19.            failedHouses++;
  20.        }
  21.    }
  22.  
  23.    if (failedHouses > 0) {
  24.        console.log(`Santa has failed ${failedHouses} houses.`);
  25.    } else {
  26.        console.log('Mission was successful.');
  27.    }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment