File tree 1 file changed +13
-13
lines changed
1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change 1
1
function printElements ( arr ) {
2
- for ( let i = 0 ; i < arr . length ; i ++ ) {
3
- if ( Array . isArray ( arr [ i ] ) ) {
4
- // Recursive case: if the element is an array, go deeper
5
- printElements ( arr [ i ] ) ;
6
- } else {
7
- // Base case: if the element is not an array, print it
8
- console . log ( arr [ i ] ) ;
9
- }
2
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
3
+ if ( Array . isArray ( arr [ i ] ) ) {
4
+ // Recursive case: if the element is an array, go deeper
5
+ printElements ( arr [ i ] )
6
+ } else {
7
+ // Base case: if the element is not an array, print it
8
+ console . log ( arr [ i ] )
10
9
}
10
+ }
11
11
}
12
12
const multiDimensionalArray = [
13
- [ 1 , 2 , [ 3 , 4 ] ] ,
14
- [ 5 , 6 ] ,
15
- [ [ 7 , 8 ] , 9 ]
16
- ] ;
13
+ [ 1 , 2 , [ 3 , 4 ] ] ,
14
+ [ 5 , 6 ] ,
15
+ [ [ 7 , 8 ] , 9 ]
16
+ ]
17
17
18
- printElements ( multiDimensionalArray ) ;
18
+ printElements ( multiDimensionalArray )
You can’t perform that action at this time.
0 commit comments