Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Created July 1, 2016 21:22
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/2b446ec1c45cc72032f3762456b728fc to your computer and use it in GitHub Desktop.
Save joshwcomeau/2b446ec1c45cc72032f3762456b728fc to your computer and use it in GitHub Desktop.
Snail
const reverse = array => [...array].reverse();
const compose = (a, b) => x => a(b(x));
const flipMatrix = matrix => (
matrix[0].map((column, index) => (
matrix.map(row => row[index])
))
);
const rotateMatrix = compose(flipMatrix, reverse);
const flipMatrixCounterClockwise = compose(reverse, rotateMatrix);
const rotateMatrixCounterClockwise = compose(reverse, flipMatrix);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment