Much has already been said in 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 this variable globally and you may be overriding values in other variables that may have the same name. Always add var
to for (var i = ...
.
In your code you are creating an object with a cash index. 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) to map the initial string. I also leave a suggestion with regex, which dispenses .indexOf
and uppercase
.
In this case the code you want could look 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 this:
(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.