Last active
February 27, 2017 22:31
-
-
Save Underdoge/b890c1f878bc8b4456d35a1c1de6ecb4 to your computer and use it in GitHub Desktop.
alternatingSums
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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