Skip to content

Instantly share code, notes, and snippets.

@aykutyaman
Created January 22, 2019 14:07
Show Gist options
  • Save aykutyaman/7337ebc242f1a6d92b2c52d3e9256e67 to your computer and use it in GitHub Desktop.
Save aykutyaman/7337ebc242f1a6d92b2c52d3e9256e67 to your computer and use it in GitHub Desktop.
short circuit reduce
const sumUntil = (a, target) =>
[...a].reduce((acc, n, _, arr) => n === target ? (arr.length = 0, acc) : acc + n)
sumUntil([1, 2, 3, 36, 4], 36) // 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment