Programming Fundamentals Final Exam 04.04.2020 - 01.Password Reset 50/100
Някой може ли да ми каже, защо джъдж ми дава 50/100 на тази задача?
Линк към задачата в джъдж
Решението ми:
https://pastebin.com/UgkhJWSW
Някой може ли да ми каже, защо джъдж ми дава 50/100 на тази задача?
Линк към задачата в джъдж
Решението ми:
https://pastebin.com/UgkhJWSW
Cut seems to be OK, but check out TakeOdd and Substitute commands where probably the remaining 50% are taken from the total score.
TakeOdd => Takes only the characters at odd indices and concatenates them together to obtain the new raw password and then prints it.
Substitute => If the raw password contains the given substring, replaces all of its occurrences with the substitute text given and prints the result.
Code (100%)
function solve(input) {
    let password = input.shift();
    let line = input.shift();
    while (line !== 'Done') {
        let [command, ...rest] = line.split(' ');
        switch (command) {
            case 'TakeOdd':
                let newPassword = '';
                for (let i = 0; i < password.length; i++) {
                    if (i % 2 !== 0) {
                        newPassword += password[i];
                    }
                }
                password = newPassword;
                console.log(password);
                break;
            case 'Cut':
                let index = Number(rest[0]);
                let length = Number(rest[1]);
                let string = password.substring(index, index + length);
                password = password.replace(string, '');
                console.log(password);
                break;
            case 'Substitute':
                let stringTarget = rest[0];
                let replace = rest[1];
                if (password.includes(stringTarget)) {
                    while (password.includes(stringTarget)) {
                        password = password.replace(stringTarget, replace);
                    }
                    console.log(password);
                } else {
                    console.log('Nothing to replace!');
                }
                break;
        }
        line = input.shift();
    }
    console.log(`Your password is: ${password}`);
}
Thank you