Skip to content
JS Fundamentals: Objects, Arrays, and Functions
Share
Explore
Functions

icon picker
Exercise: Implement filter

Prompt

Implement filter , a function that iterates over elements of collection, returning an array of all elements the callback returns truthy for. The callback is invoked with three arguments: (value, index|key, collection).
Definition: filter(collection, callback)
Example Usage:
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false }
];

filter(users, (o) => { return !o.active; });
// => [{active: false, age: 40, user: "fred"}]

Code here

Loading…

Solution

The solution is in the solution branch, which can be checked out in the by selecting the version control tab on the right and then selecting the solution branch from the drop down menu.
If you are having trouble with the solutions are also available below.

filter Solution

Next 👉


©2021 for
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.