param { number [ ] [ ] } matrix return { number [ ] } function PrintDiagonal ( matrix ) { const result = [ ] ; if ( ! matrix || matrix . length === 0 || matrix [ 0 ] . length === 0 ) { return result ; } let rows = matrix . length ; let columns = matrix [ 0 ] . length ; for ( let i = 0 ; i < rows + columns - 1 ; i ++ ) { if ( i === 0 || i % 2 === 0 ) { let x = i < rows ? i : rows - 1 ; let y = i - x ; while ( x >= 0 && y < columns ) { result . push ( matrix [ x ] [ y ] ) ; x -- ; y ++ ; } } else { let y = i < columns ? i : columns - 1 ; let x = i - y ; while ( y >= 0 && x < rows ) { result . push ( matrix [ x ] [ y ] ) ; x ++ ; y -- ; } } } return result ; } export { PrintDiagonal } ;