Skip to content

Instantly share code, notes, and snippets.

@ggteixeira
Last active July 25, 2020 01:55
Show Gist options
  • Save ggteixeira/da11da4cff928f6016ae603e1004a4f3 to your computer and use it in GitHub Desktop.
Save ggteixeira/da11da4cff928f6016ae603e1004a4f3 to your computer and use it in GitHub Desktop.
filterBy.js
// Criar um filtro por chave e valor sem usar a função filter
function filterBy(key, value, array) {
const filteredList = []
if (!key || !value) {
console.log("Key ou value é falso")
return filteredList
}
if (!Array.isArray(array) || array.length == 0) {
console.log("Não é um array ou array vazio")
return filteredList
}
array.map(carro => carro[key] === value && filteredList.push(carro))
console.log(filteredList)
return filteredList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment