Last active
June 3, 2017 16:24
-
-
Save abiodun0/60ac9bf66523d6ba4be1d6aa67b82d7f to your computer and use it in GitHub Desktop.
unfold
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
| const unfold = (f, seed) => { | |
| const go = (f, seed, acc) => { | |
| const res = f(seed); | |
| return res ? go(f, res[1], acc.concat([res[0]])) : acc | |
| } | |
| return go(f, seed, []); | |
| } | |
| unfold(x => x < 26 ? [String.fromCharCode(x+65), x + 1] : undefined, 0) // Alphabets in capital letter | |
| const range = (begin, end) => { | |
| return unfold(x => x <= end ? [x, x+1]: undefined, begin) | |
| } | |
| range(67, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment