Hello! I noticed we could use the .some()
array method instead of a separate nested for
loop and if
statement to check whether or not the input variable has a vowel. Is this a better solution to the given problem than the suggested Codecademy solution?
const input = 'a whale of a deal!';
let vowels = ['a', 'e', 'i', 'o', 'u'];
let resultArray = [];
for (let i = 0; i < input.length; i++){
//Instead of nested for loops I chose a method
//Combining a conditional and iteration of each input letter
if (vowels.some(x => x === input[i])){
resultArray.push(input[i]);
//Double E and U
if (input[i] === 'e' || input[i] === 'u'){
resultArray.push(input[i]);
};
};
};
console.log(resultArray.join('').toUpperCase());