Short JavaScript Solution
Found this solution helpful? Consider showing support by upvoting this post.\nHave a question? Kindly leave a comment below.\nThank you and happy hacking!\n\n\n
Found this solution helpful? Consider showing support by upvoting this post.\nHave a question? Kindly leave a comment below.\nThank you and happy hacking!\n\n\n```\nvar matrixReshape = function (mat, r, c) {\n    if (mat.length * mat[0].length !== r * c) return mat //Checks if a reshape is possible.\n    let elements = []\n    let reshapedMat = []\n\t\n    for (let row of mat) elements.push(...row)\n\n    for (let i = 0; i < elements.length; i += c) {\n        reshapedMat.push(elements.slice(i, i + c))\n    }\n\n    return reshapedMat\n};\n```
['JavaScript']