Hi, i have this challenge to solve, and I´m stuck for 2 days now…I´m reading a lot of stuff, and I see I can use filter method or match, but we didn’t talk about them in this platform yet, so I try different approaches, but all wrong, can anyone help me?
// the challenge:
Create a function named extractPassword which takes an array of characters (which includes some trash characters) and returns a string with only valid characters (a - z, A - Z, 0 - 9).
Here’s an example:
extractPassword([‘a’, ‘-’, ‘~’, ‘1’, ‘a’, ‘/’]); // should return the string ‘a1a’
extractPassword([’~’, ‘A’, ‘7’, ‘/’, ‘C’]); // should return the string ‘A7C’
// my code:
extractPassword(['a','º','~','z','A','&','Z','0','*','9']); {
var newPass = [];
for (var i = 0; i < extractPassword.length; i++) {
var j = extractPassword[i];
if (('a' <= j && j <= 'z')|| ('A' <= j && j <= 'Z')|| ('0' <= j && j <= '9')) {
newPass.push(j);
}
}
return newPass.join();
}
// output
Code is incorrect
syntax error
Illegal return statement