Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
feat(sum): Add module sum
Browse files Browse the repository at this point in the history
Sums a list of numbers using add
  • Loading branch information
adambrgmn committed Jan 16, 2018
1 parent 3ba5b1c commit f25cdd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/__tests__/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sum } from '../';

describe('Core.sum', () => {
test('adds all numbers in a list', () => {
expect(sum([1, 2, 3, 4])).toBe(1 + 2 + 3 + 4);
expect(sum([-1, -2, -3, -4])).toBe(-1 + -2 + -3 + -4);
});
});
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import reduceRight from './reduceRight';
import reverse from './reverse';
import slice from './slice';
import subtract from './subtract';
import sum from './sum';
import T from './T';
import update from './update';
import values from './values';
Expand Down Expand Up @@ -83,6 +84,7 @@ export {
reverse,
slice,
subtract,
sum,
T,
update,
values,
Expand Down
4 changes: 4 additions & 0 deletions src/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import add from './add';
import reduce from './reduce';

export default list => reduce(add, 0, list);

0 comments on commit f25cdd4

Please sign in to comment.