Skip to content

Instantly share code, notes, and snippets.

@yourpalsonja
Last active December 20, 2017 21:42
Show Gist options
  • Save yourpalsonja/6c88c9157e90490f73da236a113f7b7c to your computer and use it in GitHub Desktop.
Save yourpalsonja/6c88c9157e90490f73da236a113f7b7c to your computer and use it in GitHub Desktop.
var boringArray = [1,2,3,4];
const rReduce = (arr, func, acc) => {
acc ? acc : arr[0];
if(arr.length === 0) {
return acc;
}
return rReduce(arr.slice(1), func, func(acc, arr[0]))
};
const doubler = (i) => {
return i * 2;
}
const rMap = (arr, func) => {
const accumulate = (acc, e) => {
acc.push(func(e));
return acc;
};
return rReduce(arr, accumulate, [])
};
console.log(rMap(boringArray, doubler));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment