const head = ([x, ...xs]) => x; const tail = ([x, ...xs]) => xs; const map = (list, fn) => { if (list.length === 0) { return []; } else { return [fn(head(list)), ...map(tail(list), fn)]; } }; map([1, 2, 3], x => x + 1); // [2, 3, 4]