← Back to challenges

Check if One Array can be Nested in Another

JavaScriptHardarraysvalidation

Instructions

Create a function that returns true if the first array can be nested inside the second.

arr1 can be nested inside arr2 if:

  1. arr1's min is greater than arr2's min.
  2. arr1's max is less than arr2's max.

Examples

canNest([1, 2, 3, 4], [0, 6]) ➞ true

canNest([3, 1], [4, 0]) ➞ true

canNest([9, 9, 8], [8, 9]) ➞ false

canNest([1, 2, 3, 4], [2, 3]) ➞ false

Notes

Note the strict inequality (see example #3).

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: RegEx Exercise 1: Find the Time