diff --git a/lib/math.js b/lib/math.js index fc2cdddd..1460024f 100644 --- a/lib/math.js +++ b/lib/math.js @@ -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. * diff --git a/test/math.js b/test/math.js index d2eec96c..f06d82ed 100644 --- a/test/math.js +++ b/test/math.js @@ -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}}');