You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement the `keep` and `discard` operation on collections.
4
+
Given a collection and a predicate on the collection's elements, `keep` returns a new collection containing those elements where the predicate is true, while `discard` returns a new collection containing those elements where the predicate is false.
5
+
6
+
For example, given the collection of numbers:
7
+
8
+
- 1, 2, 3, 4, 5
9
+
10
+
And the predicate:
11
+
12
+
- is the number even?
13
+
14
+
Then your keep operation should produce:
15
+
16
+
- 2, 4
17
+
18
+
While your discard operation should produce:
19
+
20
+
- 1, 3, 5
21
+
22
+
Note that the union of keep and discard is all the elements.
23
+
24
+
The functions may be called `keep` and `discard`, or they may need different names in order to not clash with existing functions or concepts in your language.
25
+
26
+
## Restrictions
27
+
28
+
Keep your hands off that filter/reject/whatchamacallit functionality provided by your standard library!
29
+
Solve this one yourself using other basic tools instead.
"blurb": "Implement the `keep` and `discard` operation on collections. Given a collection and a predicate on the collection's elements, `keep` returns a new collection containing those elements where the predicate is true, while `discard` returns a new collection containing those elements where the predicate is false.",
17
+
"source": "Conversation with James Edward Gray II",
0 commit comments