Problem 42

Deep Includes Recursion Challenge

Given an array that may contain nested arrays and a target value, determine whether the target exists at any depth in the array.

Function Signature

deepIncludes(array, target)

Parameters

  • array — an array that may contain values or nested arrays.
  • target — the value to search for. May be any type including null, undefined, or false.

Output

Return true if the target is found at any nesting level, or false otherwise.

Constraints

  • The function must use recursion.
  • The input array must not be mutated.
  • The function should accept exactly two arguments.

Examples

deepIncludes([1, 2, 3], 2)                          → true
deepIncludes([1, [2, [3, 4]], 5], 4)                 → true
deepIncludes([['a'], [['b']], 'c'], 'b')             → true
deepIncludes([false, [null, [undefined]]], undefined) → true
deepIncludes([], 1)                                  → false
deepIncludes([1, [2, [3]], 4], 5)                    → false