It has already been said most of the other answers. I leave another answer with some things not yet said.
Note that when you use for (id = 0; id
you are declaring that variable globally and may be overwriting values in other variables that may have the same name. Always join var
in for (var i = ...
.
In your code you are creating an object with index cash. In this case you will have something like
{
0: 'string',
1: 'outra string',
etc...
and so it seems to me more semantic (ie more correct) map the initial string. I also leave a suggestion with regex, which dispenses with the .indexOf
and uppercase
.
In which case the code you want could be like this:
$scope.verificaVogal = function(nome) {
var vogais = ['A', 'E', 'I', 'O', 'U'];
return nome.split('').map(function(letra) {
return vogais.indexOf(angular.uppercase(letra) != -1);
});
}
or so:
$scope.verificaVogal = function(nome) {
return nome.match(/[aeiou]/i);
}
Note: if you use the first variant, I prefer it this way:
(function(){
var vogais = ['a', 'e', 'i', 'o', 'u'];
$scope.verificaVogal = function(nome) {
return nome.split('').map(function(letra) {
return vogais.indexOf(letra.toLowerCase()) != -1);
});
}
})();
to decrease whenever possible non-native code and not to declare constants within the function.
Thanks for the help Zignd!!!
– Ramaniks