0
¿¿Why the output in JavaScript is []??
const ovejas = [ { name: 'Noa', color: 'azul' }, { name: 'Euge', color: 'rojo' }, { name: 'Navidad', color: 'rojo' }, { name: 'Ki Na Ma', color: 'rojo'}, { name: 'AAAAAaaaaa', color: 'rojo' }, { name: 'Nnnnnnnn', color: 'rojo'} ] function contador(n) { return n.filter(n => n.color === 'rojo') .filter(n => `${n.name}`.includes('n')) .filter(n => `${n.name}`.includes('N')) .filter(n => `${n.name}`.includes('a')) .filter(n => `${n.name}`.includes('A')) } console.log(contador(ovejas))
1 Resposta
+ 2
It's not getting a a match and returning an empty array.
The filter is looking for name with ALL 4 letters in it.
this matches any of the letter for example.
const ovejas = [
{ name: 'Noa', color: 'azul' },
{ name: 'Euge', color: 'rojo' },
{ name: 'Navidad', color: 'rojo' },
{ name: 'Ki Na Ma', color: 'rojo'},
{ name: 'AAAAAaaaaa', color: 'rojo' },
{ name: 'Nnnnnnnn', color: 'rojo'}
]
function contador(n) {
return n.filter(n => (n.color === 'rojo' & (n.name.includes("n") | n.name.includes("N") | n.name.includes("a")) | n.name.includes("A")))
}
console.log(contador(ovejas))