//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; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter