Skip to content

Instantly share code, notes, and snippets.

View HichamBenjelloun's full-sized avatar

Hicham Benjelloun HichamBenjelloun

View GitHub Profile
@HichamBenjelloun
HichamBenjelloun / memoize-recursive.js
Last active January 2, 2022 21:38
Memoizing recursive functions
const memoizeFactory = hashFn => fn => {
const memoize = fn => {
const cache = {};
return (...args) => {
const key = hashFn(args);
if (key in cache) {
return cache[key];
}
@HichamBenjelloun
HichamBenjelloun / curry.js
Last active July 26, 2020 01:05
Currying functions
/**
* Transforms a function of the form:
* fn = (p1, ..., pN) => f(p1, ...pN)
* to its curried form:
* curried = p1 => p2 => ... => pN => fn(p1, p2, ..., pN);
*
* @param fn
* @returns the curried form of fn
*/
const curry = fn =>