Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Last active November 24, 2016 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marlysson/de8d7b332590f933991e398898231737 to your computer and use it in GitHub Desktop.
Save Marlysson/de8d7b332590f933991e398898231737 to your computer and use it in GitHub Desktop.
Array.prototype.contains = function(valor_desejado){
var quantidade = 0;
this.forEach(function(valor_atual,indice){
if (valor_atual === valor_desejado){
quantidade += 1;
}
});
if (quantidade > 0){
return true;
}
return false;
}
let nomes = [ "MARLYSSON" , "MARCELO" , "MARCOS" ]
console.log(nomes.contains("MARLYSSON"))
// true
console.log(nomes.contains("MARCELO"))
// true
console.log(nomes.contains("TESTE"))
//false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment