Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Keep Positives

Working With Arrayseasy

Course · Section 11: Working With Arrays · Lecture 156: Data Transformations: map, filter, reduce

Implement `positives(nums)` returning only the numbers greater than zero, using `filter`.

Sample tests

Input: positives([-1,2,-3,4])
Output: [2,4]
Input: positives([-1])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Including zero when only strictly positive values are wanted.

Learning resources

  • MDN: Array iteration methods
Visualize this concept: map, filter, and reduce →
Approach & explanation (try first)

filter with n > 0 returns a new array of the positive numbers.

Loading...
⌘/Ctrl + Enter

Run your code to see results.