#Best approach to compare two arrays?

1 messages · Page 1 of 1 (latest)

round gulch
#

I'm messing around with a vowel counter app, I'm sure there are plenty of different ways to return the same result. I was just curious if you could compare two arrays and return a new array of the matched values? Here's the code of what I was thinking so far. Just not sure if a high order array function could be used here or something else i'm unfamiliar with.

const input = document.querySelector('input');


submitBtn.addEventListener('click', (e) => {
    const text = input.value;
    const newArray = text.split("");
    const vowels = ['a', 'e', 'i', 'o', 'u']

});```
round gulch
#

I found a way simpler solution

const input = document.querySelector('input');


submitBtn.addEventListener('click', (e) => {
    const text = input.value;
    const vowels = text.match(/[aeiou]/ig).join("")

    console.log(vowels);
});```

Out of curiosity though, if anyone knows a way to achieve the same result by comparing functions in the original message that would be great! Thanks!