My task involves passing an array of characters to a function, extracting only letters and numbers from the array, converting those characters into a string, and returning the string. However, I am facing an issue as my function is not returning the correct value. For example, if the input array was ['A','-','5','/','v','$,'f','4','%','2','3',''], the expected output should be the string 'A5vf423'.
I am debating whether I need to declare arrayInput
or str
, but I suspect that the problem lies in how I am transferring the characters from the vector to the string.
var high = function(arrayInput) {
var str = '';
for (var i = 0; i < arrayInput; i++) {
if (arrayInput[i] >= 'a' && arrayInput[i] <= 'a' &&
arrayInput[i] >= 'A' && arrayInput[i] <= 'Z'&&
arrayInput[i] >= '0' && arrayInput[i] <= '9') {
str = arrayInput[i].join('');
}
return str
};
}
EDIT: Solution:
return arrayName.filter(character => /^[a-zA-Z0-9]/.test(character)).join("")