Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created November 26, 2025 18:27
Show Gist options
  • Select an option

  • Save goofballLogic/4f235b85d11bf0f8578ad8337c28c6e6 to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/4f235b85d11bf0f8578ad8337c28c6e6 to your computer and use it in GitHub Desktop.
const maybeAdd = (prev, candidate) =>
prev.endsAt <= candidate[1]
? [prev, {
chosen: [...prev.chosen, candidate[0]],
endsAt: candidate[2]
}]
: [prev];
const combine = ts =>
ts.reduce(
(cs, t) => cs.flatMap(prev => maybeAdd(prev, t)),
[{ chosen: [], endsAt: 0 }]
);
const choose = cs =>
cs.reduce(
(found, candidate) => found.chosen.length > candidate.chosen.length
? found
: candidate);
const summarize = x =>
({
count: x.chosen.length,
chosen: x.chosen
});
const maxMealPrepTasks = ts =>
summarize(choose(combine(ts)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment