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

icon picker
Exercise: Implement partition (bonus)

Prompt

Implement a method, partition that creates an array of elements split into two groups, the first of which contains elements callback returns truthy for, the second of which contains elements callback returns falsey for. The callback is invoked with one argument: (value).
Definition: partition(collection, callback)
Example Usage:
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true },
{ 'user': 'pebbles', 'age': 1, 'active': false }
];

partition(users, function(o) { return o.active; });
// => objects for [['fred'], ['barney', 'pebbles']]

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.

partition 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.