Skip to content

Commit

Permalink
Add a remainder helper
Browse files Browse the repository at this point in the history
  • Loading branch information
brendaniel authored and xymbol committed Jul 4, 2017
1 parent 4d2adc3 commit 36036f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ helpers.divide = function(a, b) {
return Number(a) / Number(b);
};

/**
* Get the remainder when `a` is divided by `b`.
*
* @param {Number} `a` a
* @param {Number} `b` b
* @api public
*/

helpers.remainder = function(a, b) {
return a % b;
};

/**
* Get the `Math.floor()` of the given value.
*
Expand Down
12 changes: 12 additions & 0 deletions test/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ describe('math', function() {
});
});

describe('remainder', function() {
it('should return the remainder of two numbers.', function() {
var fn = hbs.compile('{{remainder value 5}}');
assert.equal(fn({value: 7}), '2');
});

it('should take the sign of the dividend.', function() {
var fn = hbs.compile('{{remainder 5 -3}}');
assert.equal(fn(), '2');
});
});

describe('round', function() {
it('should return the value rounded to the nearest integer.', function() {
var fn = hbs.compile('{{round value}}');
Expand Down

0 comments on commit 36036f4

Please sign in to comment.