Snippets Collections
//Opción 1:
function getCount(str) {
  const vocal = str.match(/[aeiou]/ig);
  return vocal === null ? 0 : vocal.length; //si no hay vocales devuelve 0, si hay devuelve la cantidad
}

//Opción 2:
function getCount(str) {
  return str.replace(/[^aeiou]/gi, '').length;
}

//Opción 3:
function getCount(str) {
  return (str.match(/[aeiou]/ig)||[]).length;
}
star

Sat May 20 2023 17:27:25 GMT+0000 (Coordinated Universal Time) https://www.codewars.com/users/MeridaK/completed_solutions

#javascript #string #.match() #expresionesregulares #regex

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension