Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function printDeliveries(params) {
- params.pop();
- let field = params.shift().split('@');
- let santaIndex = 0;
- for (let param of params) {
- let tokens = param.split(' ');
- let jumpLength = Number(tokens[1]);
- santaIndex = (santaIndex + jumpLength) % field.length;
- if (field[santaIndex] <= 0) {
- console.log(`House ${santaIndex} will have a Merry Christmas.`);
- }
- field[santaIndex] -= 2;
- }
- console.log(`Santa's last position was ${santaIndex}.`);
- let failedHouses = 0;
- for (let house of field) {
- if (house > 0) {
- failedHouses++;
- }
- }
- if (failedHouses === 0) {
- console.log(`Mission was successful.`)
- }else{
- console.log(`Santa has failed ${failedHouses} houses.`)
- }
- }
Add Comment
Please, Sign In to add comment