let it go

Finished
44//
55
66/**
7 * @param {any[]} arr
8 * @returns {any[]}
7 * Flattens a nested array of any depth, excluding null and undefined values.
8 *
9 * @param {any[]} arr - The nested array to flatten
10 * @returns {any[]} - A flattened array with all null and undefined values removed
11 *
12 * Edge Cases Handled:
13 * - Empty arrays
14 * - Arrays with only null/undefined values
15 * - Deeply nested arrays
16 * - Mixed data types
17 * - Non-array inputs (returns empty array)
918 */
1019export const flatten = (arr) => {
11 throw new Error('Remove this line and implement the function');
20 // Edge Case: Input is not an array
21 if (!Array.isArray(arr)) {
22 return [];
23 }
24
25 const result = [];
26
27 for (const item of arr) {
28 // Edge Case: Skip null and undefined values
29 if (item === null || item === undefined) {
30 continue;
31 }
32
33 // Edge Case: Handle nested arrays
34 if (Array.isArray(item)) {
35 result.push(...flatten(item));
36 } else {
37 result.push(item);
38 }
39 }
40
41 return result;
42
43 // Handled Edge Cases: Input is not an array, Empty arrays, Arrays with only null/undefined values, Deeply nested arrays, Mixed data types, Non-array inputs
1244};
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.