Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

find First Over Threshold

Working With Arrayseasy

Course · Section 11: Working With Arrays · Lecture 164: The find Method

Implement `firstOver(arr, n)` returning the first element greater than `n`, or `null` if none.

Sample tests

Input: firstOver([1,5,8], 4)
Output: 5
Input: firstOver([1,2], 9)
Output: null

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • filter would return all matches, not just the first.
Approach & explanation (try first)

find returns the first element passing the test; ?? maps the no-match undefined to null.

Loading...
⌘/Ctrl + Enter

Run your code to see results.