Skip to content

Instantly share code, notes, and snippets.

@aSapien
aSapien / compose.js
Last active October 8, 2017 16:31
A small utility function to compose functions, lazily evaluated
function compose(func, ...funcs) {
return function(...args) {
return funcs.length > 0
? compose(...funcs)(func(...args))
: func(...args)
}
}
// Or, in a more compact version:
const compose = (func, ...funcs) => (...args) =>
@aSapien
aSapien / printMatrixInSpiral.js
Last active August 31, 2016 06:44
Print a square matrix (2x2, 4x4, 16x16, etc) in a clockwise spiral from outside in
var mat = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
];
var DIRECTIONS = {
FORWARD: 1,
BACKWARD: -1