0

I need help writing a function that returns the length of an array of characters that match "a" || "e" || "i" || "o" || "u".

function getCount(str) {
  let count = str.split("").filter((ch) => {
    return ch === "a" || "e" || "i" || "o" || "u"
  }).length;
  return count;
}

console.log(getCount("abracadabra"));
//"a" || "e" || "i" || "o" || "u"

For some reason, it is returning 11, instead of the correct value of 5.

Any help would be appreciated!

twominds
  • 1,084
  • 5
  • 20

1 Answers1

1

Sorry but you're not doing the comparison right.

function getCount(str) {
  let count = str.split("").filter((ch) => {
    return ch === "a" ||  ch ===  "e" ||  ch === "i" || ch ===  "o" || ch ===  "u"
  }).length;
  return count;
}

console.log(getCount("abracadabra"));
Jonathan Akwetey Okine
  • 1,295
  • 2
  • 15
  • 18
  • It's unfortunate that there is not a way to check a single element against multiple because this checks the same over 5 values. Anyways, thanks @Jonathan Akwetey Okine! – twominds Jun 01 '21 at 21:40
  • what are you hoping to achieve? Maybe you should update your question accordingly I thought you wanted to check the characters against the values you provided. – Jonathan Akwetey Okine Jun 01 '21 at 21:45
  • 1
    this achieves exactly what I want, sorry for the misunderstanding. I was just looking for the shortest way to check a single value against multiple values. I'm blaming JS lol. – twominds Jun 01 '21 at 21:46