Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 569 Bytes

Array Filter.md

File metadata and controls

24 lines (17 loc) · 569 Bytes

Array Filter

Write a function named filter that takes two arguments. arr (array) predicate (function)

Iterate over the elements of arr and return a new array of all elements the predicate function returns truthy for. The predicate function is invoked with one argument.

element (anything)

For example:

var users = [
  { name: 'Katie', points: 240 },
  { name: 'Ralph', points: 130 }
];

var winners = filter(users, function(element) {
  return element.points >= 200;
});

console.log(winners); // [{ name: 'Katie', points: 240 }]