JavaScript Two Pointer - Easy To Read (Notes)
\nvar matrixReshape = function(mat, r, c) {\n    const result = [];\n    \n    // Detect if the matrices can\'t map\n    if (r * c !== mat.length * mat[0].lengt
```\nvar matrixReshape = function(mat, r, c) {\n    const result = [];\n    \n    // Detect if the matrices can\'t map\n    if (r * c !== mat.length * mat[0].length) return mat;\n    \n    // Create pointers to track the original matrix\n    let pR = 0;\n    let pC = 0;\n    \n    for (let row = 0; row < r; row++) {\n        // Build a row to store the columns\n        const target = [];\n        result.push(target);\n        \n        for (let col = 0; col < c; col++) {\n            // Push the new column\n            target.push(mat[pR][pC]);\n            \n            // Update the pointer to look at the next matrix item\n            pC++;\n            \n            // If we\'ve hit undefined we\'re overflowing, move to the next row and reset the columns\n            if (mat[pR][pC] === undefined) {\n                pR++;\n                pC = 0;\n            }\n        }\n    }\n    \n    return result;\n};\n```
['Two Pointers', 'JavaScript']