my code is passing 20 out of 35 test cases, and I am not sure what fails it.
Would really appreciate assistance here, as the input is very large
function passwordCracker(pswrds, attempt) {
let buildPswrd = [];
let parsedAttempt = attempt;
while (parsedAttempt.length > 0) {
let parsedLength = parsedAttempt.length;
for (let i = 0; i < pswrds.length; i++) {
let pswrd = pswrds[i];
let l = pswrd.length;
if (parsedAttempt.slice(0, l) === pswrd) {
buildPswrd.push(pswrd);
parsedAttempt = parsedAttempt.slice(l);
break;
}
}
if (parsedLength === parsedAttempt.length) return 'WRONG PASSWORD';
}
let answer = buildPswrd.join(' ')
console.log(answer);
return answer;
}
//link to challenge
// https://www.hackerrank.com/challenges/password-cracker/problem?utm_campaign=challenge-recommendation&utm_medium=email&utm_source=24-hour-campaign