param { number [ ] [ ] } arr return { number [ ] } function PrintMatrix ( arr ) { let start = 0 ; let rows = arr . length ; let columns = arr [ 0 ] ? arr [ 0 ] . length : 0 ; const result = [ ] ; if ( ! rows || ! columns ) { return result ; } while ( columns > start * 2 && rows > start * 2 ) { printCircle ( arr , start , columns , rows , result ) ; start ++ ; } return result ; } param { number [ ] [ ] } arr param { number } start param { number } columns param { number } rows param { number [ ] } result function printCircle ( arr , start , columns , rows , result ) { let x = columns - start - 1 ; let y = rows - start - 1 ; for ( let i = start ; i <= x ; i ++ ) { result . push ( arr [ start ] [ i ] ) ; } if ( y > start ) { for ( let i = start + 1 ; i <= y ; i ++ ) { result . push ( arr [ i ] [ x ] ) ; } if ( x > start ) { for ( let i = x - 1 ; i >= start ; i -- ) { result . push ( arr [ y ] [ i ] ) ; } if ( y > start + 1 ) { for ( let i = y - 1 ; i > start ; i -- ) { result . push ( arr [ i ] [ start ] ) ; } } } } } export { PrintMatrix } ;