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:
var password = ['a','º','~','z','A','&','Z','0','*','9'];
var newPass = [];
var arrayLength = password.length;
function extractPassword(password) {
for (var i = 0; i < arrayLength; i++) {
var j = password[i];
if (('a' <= j && j <= 'z')|| ('A' <= j && j <= 'Z')|| ('0' <= j && j <= '9')) {
newPass.push(j);
}
}
return newPass.join('');
}
extractPassword(password);
console.log(newPass);```
// output:
[
"a",
"z",
"A",
"Z",
"0",
"9"
]
I´m stuck on this for 2 days, I´m getting blind ,I rewrite my code a lot of times ,but I still can't see what am I doing wrong....