Skip to content

Instantly share code, notes, and snippets.

@Osukaru
Created August 16, 2011 12:06
Show Gist options
  • Save Osukaru/1148934 to your computer and use it in GitHub Desktop.
Save Osukaru/1148934 to your computer and use it in GitHub Desktop.
Mi solución al segundo ejercicio para el tercer día de gejs
maximoNumeroVocales = function (obj) {
maximo = 0;
contarVocales = function (obj) {
var objNormalizado = obj.toLowerCase().replace(/[á]/, "a").replace(/[é]/,"e").replace(/[í]/, "i").replace(/[ó]/, "o").replace(/[úü]/, "u"),
vocales = ["a", "e", "i", "o", "u"],
contador = 0,
lugarVocal;
for (var i = 0; i < obj.length; i++) {
lugarVocal = vocales.indexOf(objNormalizado [i]);
if (lugarVocal != -1) {
delete vocales[lugarVocal];
contador++;
}
}
return contador;
}
desarraygar = function (obj) {
var numVocales;
if (({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase() == "string") {
numVocales= contarVocales(obj);
if (numVocales > maximo) {
maximo = numVocales;
}
}
else {
for (var i=0; i<obj.length; i++) {
result = desarraygar(obj[i]);
}
}
return(maximo);
}
return desarraygar (obj);
}
console.log(maximoNumeroVocales (["hola", ["soy", ["juan", "fernández"] ], "y", ["no", "tengo", ["dinero"] ] ]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment