# Unravelling the Matrix Array.

`// Sample Array (4 x 4 matrix)//  1  2  3  4//  12 13 14 5//  11 16 15 6//  10 9  8  7matrix = [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]]// expected output[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]`
`function unrollMatrix(matrix){    // grab top row    // grab right column    // grab bottom row and reverse it    // grab left column and reverse it}`
`function unrollMatrix(matrix){   let unrolled = []// grab top row   unrolled = [...unrolled, matrix.shift()]// grab right column// grab bottom row and reverse it// grab left column and reverse it}`
`function unrollMatrix(matrix){    let unrolled = []// grab top row    unrolled = [...unrolled, matrix.shift()]// grab right column    unrolled = [...unrolled, matrix.map(row => row.pop())]// grab bottom row and reverse it// grab left column and reverse it}`
`function unrollMatrix(matrix){    let unrolled = []// grab top row    unrolled = [...unrolled, matrix.shift()]// grab right column    unrolled = [...unrolled, matrix.map(row => row.pop())]// grab bottom row and reverse it    unrolled = [...unrolled, matrix.pop().reverse()]// grab left column and reverse it}`
`function unrollMatrix(matrix){    let unrolled = []// grab top row    unrolled = [...unrolled, matrix.shift()]// grab right column    unrolled = [...unrolled, matrix.map(row => row.pop())]// grab bottom row and reverse it    unrolled = [...unrolled, matrix.pop().reverse()]// grab left column and reverse it     unrolled = [...unrolled, matrix.map(row => row.shift()).reverse()]}`
`function unrollMatrix(matrix){let unrolled = []while (matrix.length > 0) {// grab top row    unrolled = [...unrolled, matrix.shift()]// grab right column    unrolled = [...unrolled, matrix.map(row => row.pop())]// grab bottom row and reverse it    unrolled = [...unrolled, matrix.pop().reverse()]// grab left column and reverse it    unrolled = [...unrolled, matrix.map(row => row.shift()).reverse()]}return unrolled.flat()}`

--

--