Created
August 3, 2019 08:37
-
-
Save bfunc/320448ed235caf8703fd5391411d8a2e to your computer and use it in GitHub Desktop.
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 lessThan = function(end, value) { | |
return function(value) { | |
return value < end; | |
}; | |
} | |
// 25 alphabet character letters | |
const lessThan26 = lessThan(26); | |
const lazyMap = function* (iterable, callback) { | |
for (let value of iterable) { | |
yield callback.call(this, value); | |
} | |
}; | |
const numberToAlphabet = function(value) { | |
//97 in ASCII is 'a' | |
//Our min value is 1 | |
return String.fromCharCode(96 + value); | |
}; | |
const numbers = [...randomNumberGenerator(10)]; | |
console.log(numbers); | |
//[ 74, 16, 74, 24, 54, 96, 1, 71, 71, 77 ] | |
//Our chained generator object | |
let alphabebtCharIterator = lazyMap(filter(numbers), lessThan26), numberToAlphabet); | |
alphabetCharIterator.next(); | |
//{ value: 'o', done: false } | |
alphabetCharIterator.next(); | |
//{ value: 'w', done: false } | |
alphabetCharIterator.next(); | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment