nikolayneykov

Untitled

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