Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Created July 1, 2016 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshwcomeau/8a9c4f2ed3ab32514fdd4886e8e26e24 to your computer and use it in GitHub Desktop.
Save joshwcomeau/8a9c4f2ed3ab32514fdd4886e8e26e24 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())
);
const rotateMatrixCounterClockwise = matrix => (
flipMatrix(matrix).reverse()
);
const flipMatrixCounterClockwise = matrix => (
rotateMatrix(matrix).reverse()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment