Last active
July 25, 2020 01:55
-
-
Save ggteixeira/da11da4cff928f6016ae603e1004a4f3 to your computer and use it in GitHub Desktop.
filterBy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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