Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Last active July 20, 2016 12:28
Show Gist options
  • Save joshwcomeau/af4974413aa90d9372723231b49aba65 to your computer and use it in GitHub Desktop.
Save joshwcomeau/af4974413aa90d9372723231b49aba65 to your computer and use it in GitHub Desktop.
Snail
const flipMatrix = matrix => (
matrix[0].map((column, index) => (
matrix.map(row => row[index])
))
);
const rotateMatrix = matrix => (
flipMatrix(matrix.reverse())
);
/*
Sure enough, this function rotates the matrix clockwise:
[ [
[1,2,3], [7,4,1],
[4,5,6], -> [8,5,2],
[7,8,9], [9,6,3],
]; ];
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment