Last active
June 27, 2020 14:24
-
-
Save joefearnley/7ad8d4395f94875153a55dfdfc36f965 to your computer and use it in GitHub Desktop.
10 day JS challenge - Day 3: Alternating Sums
This file contains 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
const alternatingSums = weights => [ | |
weights.filter((weight, i) => i % 2 === 0).reduce((a, c) => a + c), | |
weights.filter((weight, i) => i % 2 !== 0).reduce((a, c) => a + c) | |
]; | |
describe('alternatingSums()', () => { | |
it('returns alternating sums of even and odd', () => { | |
// arrange | |
const nums = [50, 60, 60, 45, 70]; | |
// act | |
const result = alternatingSums(nums); | |
// log | |
console.log("result: ", result); | |
// assert | |
expect(result).toEqual([180, 105]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment