Skip to content

Instantly share code, notes, and snippets.

@larizzatg
Created April 12, 2020 17:15
Show Gist options
  • Save larizzatg/9e0f49d400a7f279cf07040cd14acb2e to your computer and use it in GitHub Desktop.
Save larizzatg/9e0f49d400a7f279cf07040cd14acb2e to your computer and use it in GitHub Desktop.
learning how to do a unary function
const _ = {};
_.map = (arr, fn) => {
const results = [];
for(let i = 0; i < arr.length; i++) {
results.push(fn(arr[i]));
}
return results;
};
_.unary = (fn) => {
return (value) => {
return fn(value);
};
};
const result = _.map(['6', '8', '10'], _.unary(parseInt));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment