Skip to content

Instantly share code, notes, and snippets.

@jerlyrosa
Created September 7, 2020 00:41
Show Gist options
  • Save jerlyrosa/469e63e9f78951889b84b2f05e8c1c1a to your computer and use it in GitHub Desktop.
Save jerlyrosa/469e63e9f78951889b84b2f05e8c1c1a to your computer and use it in GitHub Desktop.
Funcion para comprender como trabaja el metodo filter() en javascript
// Problema para dar a entender o dar la idea de como funciona el metodo filter teniendiendo en cuenta
// que ya sabes algo de su parte teorica.
var arr = [1,2, 2, 4,];// Array original
const arrayFilter=(arr)=>{
let result = arr.filter( (element, index, array) =>{
console.log(element);// Primer elemento del Array
console.log(index);// indice de cada Array
console.log(array)// copia de Array original;
return element === 2// condicion
});
return console.log(result)// result = [ 2, 2 ]
}
arrayFilter(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment