Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Filter by Predicate Name

A Closer Look at Functionsmedium

Course · Section 10: A Closer Look at Functions · Lecture 137: First-Class and Higher-Order Functions

Implement `filterBy(nums, kind)` returning the numbers matching the predicate named by `kind`: `even`, `odd`, or `positive`.

Sample tests

Input: filterBy([1,2,3,4], "even")
Output: [2,4]
Input: filterBy([-1,2,-3], "positive")
Output: [2]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Hardcoding one predicate instead of selecting by name.

Learning resources

  • MDN: Array iteration methods
Visualize this concept: Higher-Order Functions →
Approach & explanation (try first)

Selecting a predicate from a map and passing it to filter shows functions used as values.

Loading...
⌘/Ctrl + Enter

Run your code to see results.