Created
August 16, 2011 13:39
-
-
Save javierbrea/1149088 to your computer and use it in GitHub Desktop.
Solucion al ejercicio Vocales Diferentes #gejs
This file contains 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
var example=["hola",3,["soy",function(){}, ["juán", "férnaaández"] ], "y",new Date(), ["no", "tüungo",function(){},["dínero",[]] ] ]; | |
var mayorNumeroVocales=function(obj){ | |
var vocales=[/[aáãàâä]/,/[eéêèë]/,/[iíîìï]/,/[oóõòôö]/,/[uúùûü]/], | |
cuentaVocales=function(str){ | |
var presentes=0; | |
for (var i=0,z=vocales.length; i<z; i++) { | |
if(str.match(vocales[i])){ | |
presentes++; | |
} | |
} | |
return presentes; | |
}, | |
calcula=function(obj){ | |
var maxVocales=0; | |
if(typeof(obj)=='string'){ | |
return cuentaVocales(obj); | |
} | |
if (Array.isArray(obj)){ | |
for(var i=0,z=obj.length;i<z;i++){ | |
var currentVocales=mayorNumeroVocales(obj[i]); | |
if(maxVocales<currentVocales){ | |
maxVocales=currentVocales; | |
} | |
} | |
} | |
return maxVocales; | |
} | |
return calcula(obj); | |
}; | |
mayorNumeroVocales(example); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Código revisado para retirar la función "quitaAcentos" por innecesaria. Al añadir las vocales tildadas al array de vocales no es necesario ejecutarla.