diff --git a/addon/helpers/sum.js b/addon/helpers/sum.js new file mode 100644 index 00000000..cccbf98c --- /dev/null +++ b/addon/helpers/sum.js @@ -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); diff --git a/app/helpers/sum.js b/app/helpers/sum.js new file mode 100644 index 00000000..ec9a53f6 --- /dev/null +++ b/app/helpers/sum.js @@ -0,0 +1 @@ +export { default, sum } from 'ember-math-helpers/helpers/sum'; diff --git a/tests/unit/helpers/sum-test.js b/tests/unit/helpers/sum-test.js new file mode 100644 index 00000000..110a41ea --- /dev/null +++ b/tests/unit/helpers/sum-test.js @@ -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)); + }); +});