Repository navigation
#232 One Array Nested in Another
Adam Kubiś edited this page Oct 28, 2026
·
1 revision
Create a function that returns true if the first array can be nested inside the second and false otherwise.
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/232 One Array Nested in Another.js"Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.
This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.
//Create a function that returns true if the first array can be nested inside the second and false otherwise.
function canNest(arr1, arr2) {
return Math.min(...arr1) > Math.min(...arr2) && Math.max(...arr1) < Math.max(...arr2);
}
import { assertEquals } from '../testHelper.js';
assertEquals(canNest([1, 2, 3, 4], [0, 6]), true)
assertEquals(canNest([3, 1], [4, 0]), true)
assertEquals(canNest([9, 9, 8], [8, 9, 10]), false)
assertEquals(canNest([9, 9, 8], [8, 9]), false)
assertEquals(canNest([1, 2, 3, 4], [2, 3]), false)