Skip to content

Commit

Permalink
implement sum helper as strict alias for add helper (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mifrill authored Oct 19, 2021
1 parent 90a7dbc commit a012f13
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions addon/helpers/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { helper } from '@ember/component/helper';
import { add } from './add';

/**
* Alias for {{add}} helper
*
* ```hbs
* {{sum a b}}
* ```
*
* @param {number[]} numbers A list of numbers to sum
* @return {number} The sum of all the passed numbers
*/
export function sum(numbers) {
return add(numbers);
}

export default helper(sum);
1 change: 1 addition & 0 deletions app/helpers/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, sum } from 'ember-math-helpers/helpers/sum';
15 changes: 15 additions & 0 deletions tests/unit/helpers/sum-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { sum } from 'dummy/helpers/sum';
import { add } from 'dummy/helpers/add';
import { module, test } from 'qunit';

module('Unit | Helper | sum', function () {
test('works as alias to add', function (assert) {
const input = [20, 10];
assert.strictEqual(sum(input), add(input));
});

test('works as alias to add for multiple arguments', function (assert) {
const input = [1, 2, 3, 4, 5];
assert.strictEqual(sum(input), add(input));
});
});

0 comments on commit a012f13

Please sign in to comment.