Skip to content

Instantly share code, notes, and snippets.

@kijuky
Last active June 25, 2020 16:53
Show Gist options
  • Save kijuky/2ac56c388124c8b8f1dcab040672881a to your computer and use it in GitHub Desktop.
Save kijuky/2ac56c388124c8b8f1dcab040672881a to your computer and use it in GitHub Desktop.
const arr = [ ... ]; // なにか配列
const pred = e => ...; // なにか述語
const {result} = arr.reduce((acc, cur) => {
if (acc.finished) { return acc; }
acc.finished = !pred(cur);
if (acc.finished) { return acc; }
acc.result.push(cur);
return acc;
}, {result: [], finished: false});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment