Skip to content

Instantly share code, notes, and snippets.

@cristianobecker
Created September 23, 2014 19:59
Show Gist options
  • Save cristianobecker/241ec015ff197fb56641 to your computer and use it in GitHub Desktop.
Save cristianobecker/241ec015ff197fb56641 to your computer and use it in GitHub Desktop.
Obter somente vogais
var utils = {};
utils.vogal = function (str) {
var h = Object.prototype.hasOwnProperty,
v = (str + '').replace(/[^aeiou]/g, ''),
d = {},
n;
for (var i in v) {
n = v[i];
if (h.call(d, n)) {
d[n]++;
} else {
d[n] = 1;
}
}
return d;
};
@cristianobecker
Copy link
Author

utils.vogal('uma frase de teste');     // { u: 1, a: 2, e: 4 }
utils.vogal('banana');                 // { a: 3 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment