Last active
June 30, 2018 18:07
-
-
Save matyasfodor/f8cc5f33940a0456634a60ffaaeb9d0d 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 sizedArray = (n) => Array(n).fill(); | |
const times = (n, cb) => { | |
while (0 < n--) { | |
cb(); | |
} | |
} | |
const fillWithCb = (n, cb) => sizedArray(n).map(cb); | |
const nWise = n => array => { | |
iterators = fillWithCb(n, () => array[Symbol.iterator]()); | |
iterators.forEach((it, index) => times(index, () => it.next())); | |
return fillWithCb( | |
array.length - n + 1, | |
() => iterators.map(it => it.next().value), | |
); | |
}; | |
const pairWise = nWise(2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment