Skip to content

Instantly share code, notes, and snippets.

@Underdoge
Last active February 27, 2017 22:31
Show Gist options
  • Save Underdoge/b890c1f878bc8b4456d35a1c1de6ecb4 to your computer and use it in GitHub Desktop.
Save Underdoge/b890c1f878bc8b4456d35a1c1de6ecb4 to your computer and use it in GitHub Desktop.
alternatingSums
function alternatingSums(a) {
var sum = a.reduce(function(acc, val,currentIndex) {
if(currentIndex%2==0)
acc[0] += val;
else
acc[1] += val;
return acc;
}, [0,0]);
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment