function add ( ... numbers ) { return numbers . reduce ( function ( sum , number ) { return sum + number ; } ) ; } console . log ( add ( 1 , 2 , 3 , 4 , 5 ) ) ; interface MultiDimensionArray < T > { [ key ] : T | MultiDimensionArray < T > ; length : number ; } function flatten < T > ( array , result = [ ] ) { for ( let i = 0 ; i < array . length ; i ++ ) { if ( Array . isArray ( array [ i ] ) ) { flatten ( array [ i ] as T [ ] , result ) ; } else { result . push ( array [ i ] as T ) ; } } return result ; } console . log ( flatten ( [ 1 , [ 2 , 3 , [ 4 , 5 ] , 6 , 7 ] , 8 ] ) ) ; console . log ( flatten ( [ [ [ [ [ [ 10 ] ] ] ] ] ] , [ 1 , 5 ] ) ) ;