Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
vowelcounter
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);
@jeroldangarcia

This comment has been minimized.

Copy link
Owner Author

jeroldangarcia commented Aug 17, 2011

llevas razon!!! lo modifico un poco....

@jeroldangarcia

This comment has been minimized.

Copy link
Owner Author

jeroldangarcia commented Aug 17, 2011

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
You can’t perform that action at this time.