Created
April 12, 2020 17:15
-
-
Save larizzatg/9e0f49d400a7f279cf07040cd14acb2e to your computer and use it in GitHub Desktop.
learning how to do a unary function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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