Created
February 26, 2019 13:43
-
-
Save wwqrd/faf18b5fc001fd6137ff08cc1e6a2a02 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
// Input | |
const input = ['a', 'b', 'c', 'd']; | |
// Output | |
// const expectedOut = [ | |
// ['a'] | |
// ['a', 'b'] | |
// ['a', 'b', 'c'] | |
// ['a', 'b', 'c', 'd'] | |
// ['b'] | |
// ['b', 'c'] | |
// ['b', 'c', 'd'] | |
// ['c'] | |
// ['c', 'd'] | |
// ['d'] | |
//]; | |
const sliceLeft = (_, i, list) => | |
list.slice(0, i + 1); | |
const getInterestingList = boringList => | |
boringList.reduce( | |
(memo, _, i, list) => | |
memo.concat(list.slice(i).map(sliceLeft)), | |
[] | |
); | |
console.log(getInterestingList(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment