Created
August 16, 2011 18:00
-
-
Save jeroldangarcia/1149731 to your computer and use it in GitHub Desktop.
vowelcounter
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
function VowelCounter() { | |
this.vowels = "aãàáäâeèéëêiìíïîoòóöôuùúüû"; | |
this.to = "aaaaaaeeeeeiiiiiooooouuuuu"; | |
this.mapping = {}; | |
for(var i = 0, j = this.vowels.length; i < j; i++ ) | |
this.mapping[ this.vowels.charAt( i ) ] = this.to.charAt( i ); | |
} | |
VowelCounter.prototype.maxCountInASet = function(arrayBuffer) { | |
var tokens = arrayBuffer.join().toLowerCase().split(','); | |
var maxCount = 0; | |
for (var i=tokens.length-1; i>=0; i--) { | |
var tokenCount = this.countInAWord(tokens[i]); | |
maxCount = maxCount < tokenCount ? tokenCount : maxCount; | |
} | |
return maxCount; | |
}; | |
VowelCounter.prototype.countInAWord = function(word) { | |
var count = 0; | |
var alreadyCounted = []; | |
for (var i=word.length-1;i>=0;i--){ | |
var letter = this.isVowel(word.charAt(i)) ? this.vowelNormalizer(word.charAt(i)) : word.charAt(i); | |
if (this.isVowel(letter) && alreadyCounted.indexOf(letter) == -1){ | |
alreadyCounted.push(letter); | |
count++; | |
} | |
} | |
return count; | |
}; | |
VowelCounter.prototype.isVowel = function(vowel) { | |
return this.vowels.indexOf(vowel) != -1; | |
}; | |
VowelCounter.prototype.vowelNormalizer = function(vowel) { | |
if( this.mapping.hasOwnProperty(vowel)) | |
return this.mapping[ vowel ]; | |
else | |
return vowel; | |
}; | |
var vowelCounter = new VowelCounter() ; | |
var result = vowelCounter.maxCountInASet(["hoooooola", ["soy", ["juan", "fernáaaandez"] ], "y", ["no", "tengo", ["dinero"] ] ]); | |
console.log(result); |
mecachis!!! lo mejoro un poco robando la tecnica del mapping de vocales para normalizar de etnasoft http://www.etnassoft.com/2011/03/03/eliminar-tildes-con-javascript/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
llevas razon!!! lo modifico un poco....