Skip to content

Instantly share code, notes, and snippets.

@wwqrd
Created February 26, 2019 13:43
Show Gist options
  • Save wwqrd/faf18b5fc001fd6137ff08cc1e6a2a02 to your computer and use it in GitHub Desktop.
Save wwqrd/faf18b5fc001fd6137ff08cc1e6a2a02 to your computer and use it in GitHub Desktop.
// 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