Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as JavaScript by JakubUrbanPassword ( 6 years ago )
function password(str) {
    let results = -1;
    let potentialPassword = ""
    let characters = str.split("");

    function check() {
        if (potentialPassword.length > 0) {
            results += results === -1 ? 2 : 1;
        }
    }

    function clear() {
        check();
        potentialPassword = "";
    }

    function add(char) {
        potentialPassword += char;
    }

    characters.forEach(c => {
        // Number 
        if (!isNaN(c)) {
            clear();
            return
        }

        const isUppercase = c === c.toUpperCase();
        if (potentialPassword.length === 0) {
            // Starting Letter
            if (isUppercase) {
                add(c);
                return
            }
        } else {
            // Regular Letter
            if (!isUppercase) {
                add(c);
                return
            } else {
                // Starting Of Next Valid Password After Another Valid Password
                clear();
                add(c);
                return;
            }
        }

        // Nothing Above
        clear();
    })

    check();

    return results;
}

console.log(password("aB1Cx")); // 2
console.log(password("X8xcFvF")); // 3
console.log(password("abc1Fx2cv")); // 1

 

Revise this Paste

Your Name: Code Language: