infinito
New Coder
I'm doing a test for a Bootcamp. Stuck on this problem.
Here is the problem:
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:
MY CODE:
ISSUE: The auto-correct of the test platform says "
>>>>Code is incorrect
Your function is not returning the correct value"
Can't use RegEx btw.
Can you see the issue? I really need to get into this Bootcamp. Thanks in advance.
Here is the problem:
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:
Code:
extractPassword(['a', '-', '~', '1', 'a', '/']); // should return the string 'a1a'
extractPassword(['~', 'A', '7', '/', 'C']); // should return the string 'A7C'
MY CODE:
Code:
var extractPassword = function (array) {
var validChar = [];
for (var i = 0; i < array.length; i++) {
if ('a' <= array[i] && array[i] <= 'z' || 'A' <= array[i] && array[i] <= 'Z' || '1' <= array[i] && array[i] <= '9') {
validChar.push(array[i]);
}
}
return validChar.join('');
};
console.log (extractPassword (['a', '~', '-', '1', 'a', '/'])); // console returns a1a correctly
ISSUE: The auto-correct of the test platform says "
>>>>Code is incorrect
Your function is not returning the correct value"
Can't use RegEx btw.
Can you see the issue? I really need to get into this Bootcamp. Thanks in advance.
