future

Finished
44//
55
66/**
7 * @param {any[]} arr
8 * @returns {any[]}
7 * Flattens a nested array of any depth, excluding null-like values.
8 *
9 * @param {any[]} arr - The nested array to flatten
10 * @returns {any[]} - A flattened array with null-like values removed
911 */
1012export const flatten = (arr) => {
11 throw new Error('Remove this line and implement the function');
13 // Edge Case: Handle null or undefined input
14 if (arr === null || arr === undefined) {
15 return [];
16 }
17
18 // Edge Case: Handle non-array input
19 if (!Array.isArray(arr)) {
20 return [];
21 }
22
23 const result = [];
24
25 for (const item of arr) {
26 // Edge Case: Skip null-like values (null and undefined)
27 if (item === null || item === undefined) {
28 continue;
29 }
30
31 // Edge Case: Recursively flatten nested arrays
32 if (Array.isArray(item)) {
33 const flattened = flatten(item);
34 result.push(...flattened);
35 } else {
36 // Edge Case: Include non-array items of any type (string, number, boolean, object, etc.)
37 result.push(item);
38 }
39 }
40
41 return result;
1242};
43
44// Handled Edge Cases: null/undefined input, non-array input, null/undefined elements, nested arrays of any depth, mixed data types in array
Test NameStatus
empty
Pass
no nesting
Pass
flattens a nested array
Pass
flattens array with just integers present
Pass
5 level nesting
Pass
6 level nesting
Pass
undefined values are omitted from the final result
Pass
null values are omitted from the final result
Pass
consecutive null values at the front of the array are omitted from the final result
Pass
consecutive null values in the middle of the array are omitted from the final result
Pass
6 level nested array with null values
Pass
all values in nested array are null
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.