Hey all,
being a beginner at JavaScript I was really happy about finding this solution on how to pull the vowels out from my phrase AND removing the duplicates in the new array. Totally not needed for this project but feels like a solution that could be good to know for the future.
i used the match() function together with some regex to pull the vowels and the the Set() function to remove the duplicates.
Initially, I wanted to push both small and capital letters into the resultArray, since i believe whales don’t always scream in all caps but couldn’t find a solution for it. But here’s my result. I hope the Set() and match() can come in handy for someone
const input = 'I am Andy from Sweden. And you?'
const regex = /[AaEeIiOoUu]/g; // used to match vowels in input
const vowels =[...new Set(input.match(regex))];
/* input.match(regex)) pulls the vowels out from input. creates array from regex function, with duplicate if any. [...new Set()] creates a new array without duplicates */
let resultArray = [];
for (i = 0; i < input.length; i++){ // counts through the length of input
for(j = 0; j < vowels.length; j++) { // counts through the length of vowels
if (input[i] === vowels[j]) { //compares input with vowels
if (input[i] === 'e') {
resultArray.push('ee');
} else if (input[i] === 'u') {
resultArray.push('uu');
} else {
resultArray.push(input[i]); // else if that checks if vowels in input = vowels and doubles the e's and u's. pushes results into resultArray.
}
}
}
}
console.log(resultArray.join('').toUpperCase());
Have a good week!
Andy