Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
Can you filter characters (even duplicated) from an array?

const stringConvert = string => {
  let splitString = string.split("");
  let vowels = splitString.filter(letters => {
    return letters === "a", "e", "i", "o", "u"
  })
  return console.log(vowels);
};


stringConvert("Why don't you try and split this string into vowels, please?");

The code above comes back undefined and I am trying to create a function that takes a string and counts how many vowels are in it. So far I have used the .split() to create an array with each individual character of the string and then I tried using .filter() to filter out each character that is a vowel.

What (only vanilla javascript) would allow me to filter out each vowel from an array, so then I could use .length on that array to get the number of vowels?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const stringConvert = string => {
  let splitString = string.split("");
  let vowels = ["a", "e", "i", "o", "u"];
  let letters = {};
  splitString.forEach(l => {
    letters[l] = letters[l] ? letters[l] + 1 : 1;
  })
  let vowelsCount = [];
  vowels.forEach(l => vowelsCount[l] = letters[l]);
  return vowelsCount;
};
stringConvert("Why don't you try and split this string into vowels, please?");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!