Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function heartDelivery(input) {
- let houses = input.shift().split('@').map(Number);
- let index = 0;
- while (input[0] !== 'Love!') {
- index += Number(input.shift().slice(5));
- if (index >= houses.length){
- index = 0;
- }
- if (houses[index] == 0) {
- console.log(`Place ${index} already had Valentine's day.`);
- } else {
- houses[index] -= 2;
- if (houses[index] == 0) {
- console.log(`Place ${index} has Valentine's day.`);
- }
- }
- }
- console.log(`Cupid's last position was ${index}.`);
- let houseCount = houses.filter(x => x !== 0).length;
- console.log(houseCount === 0 ? 'Mission was successful.' : `Cupid has failed ${houseCount} places.`);
- return;
- }
Advertisement
Advertisement