Created
August 16, 2011 12:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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