Last active
June 27, 2017 05:49
-
-
Save dewey92/d8fec123d8806803731c0e6b25dc8ad8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // filter :: (a → Bool) → [a] → [a] | |
| const filter = fn => arr => arr.filter(fn) | |
| // isEven :: Int → Bool | |
| const isEven = num => num % 2 === 0 | |
| // oneToSix :: [Int] | |
| const oneToSix = [1, 2, 3, 4, 5, 6] | |
| // filterEvenNumbers :: [Int] | |
| const filterEvenNumbers = filter(isEven)(oneToSix) | |
| # [2, 4, 6] | |
| // reduce :: (b → a → b) → b → [a] → b | |
| const reduce = (fn, init) => arr => arr.reduce(fn, init) | |
| // addStrLength :: Int → String → Int | |
| const addStrLength = (acc, x) => acc + x.length | |
| // init :: Int | |
| const init = 0 | |
| // myName :: [String] | |
| const myName = ['Jihad', 'Dzikri'] | |
| // computeStringLength :: Int | |
| const computeStringLength = reduce(addStrLength, init)(myName) | |
| # 11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment