JS Built-ins
← Array71 / 226
ArrayArray.prototype.findintermediate

Array.prototype.find() β€” find in range

πŸ“– Usage Example
const pts = [{x:1,y:1}, {x:2,y:3}, {x:3,y:4}]
pts.find(p => p.x + p.y > 4)  // β†’ {x:2, y:3}

Use find() with a complex predicate to locate an object satisfying multiple conditions.

Array.prototype.find() β€” compound conditions

find() predicates can be as complex as needed. Multiple conditions can be combined with && to narrow the search.

Challenge: Implement findInRange(nums, lo, hi) that returns the first number between lo and hi (inclusive).

findInRange([1, 5, 3, 8, 6], 4, 7) // β†’ 5
findInRange([1, 2, 3], 10, 20)     // β†’ undefined
πŸ’‘ Hints (2)
  • β€’ Combine conditions with `&&`: `n >= lo && n <= hi`.
  • β€’ Remember: `find` returns the first element that satisfies the condition in array order.