Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

315
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda