{"size": 1599, "ext": "js", "max_stars_repo_path": "JS-fundamentals-may-2019/Mid Exams/Mid Exam - 18 December 2018/3. Present Delivery.js", "max_stars_repo_name": "uzuntonev/SoftUni-software-engineering-js", "max_stars_repo_stars_event_min_datetime": "2019-07-15T18:17:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-30T07:08:47.000Z", "max_issues_repo_path": "JS-fundamentals-may-2019/Mid Exams/Mid Exam - 18 December 2018/3. Present Delivery.js", "max_issues_repo_name": "uzuntonev/SoftUni-Software-Engineering-JS", "max_issues_repo_issues_event_min_datetime": "2021-05-11T13:38:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T13:40:16.000Z", "max_forks_repo_path": "JS-fundamentals-may-2019/Mid Exams/Mid Exam - 18 December 2018/3. Present Delivery.js", "max_forks_repo_name": "uzuntonev/SoftUni-software-engineering-js", "max_forks_repo_forks_event_min_datetime": "2019-11-29T19:48:46.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-29T19:48:46.000Z"}
{"max_stars_count": 3, "max_issues_count": 3, "max_forks_count": 1, "avg_line_length": 28.5535714286, "max_line_length": 81, "alphanum_fraction": 0.5390869293}
function solve(input) {
    let houses = input.shift().split('@').map(Number);
    let santaPosition = 0;
    while (true) {
        let [command, steps] = input.shift().split(' ');
        steps = Number(steps);
        if (command === 'Merry') {
            break;
        }
        // Calculate on which position santa stop
        let position = (startPosition, jump) => {
            if ((startPosition + jump) >= houses.length) {
                return startPosition = (startPosition + jump) % houses.length;
            } else {
                return startPosition += jump;
            }

        }

        // Assignment santa position with returned value from function position()
        santaPosition = position(santaPosition, steps)

        // Substract each house where is stop sant with 2 and check is it under 0
        houses[santaPosition] -= 2;
        if (houses[santaPosition] < 0) {
            houses[santaPosition] = 0;
            console.log(`House ${santaPosition} will have a Merry Christmas.`);
        }

    }
    let failedHouse = (houses.filter(e => e > 0)).length
    if (failedHouse == 0) {
       
        console.log(`Santa's last position was ${santaPosition}.`);
        console.log(`Mission was successful.`);
    } else {
        console.log(`Santa's last position was ${santaPosition}.`);
        console.log(`Santa has failed ${failedHouse} houses.`);

    }
}

// solve(['10@10@10@2',
//     'Jump 1',
//     'Jump 2',
//     'Merry Xmas!'

// ]);
solve(['2@4@2',
    'Jump 2',
    'Jump 2',
    'Jump 8',
    'Jump 3',
    'Jump 1',
    'Merry Xmas!'
]);