$.number.calc

Calc method of number helpers

This calc method only useful when we use array of objects, we can declare or create a property separately for left operand, right operand and operator. Operand must be in a number and operator is in a string with value either add or (addition, plus, or +), subtract or (subtraction, minus, or -), multiply or (multiplication, × or *), divide or (division, ÷ or /), remainder or (modulo or %), or exponent (exponentiation or **).

$.number.calc(leftOperand, rightOperand, operator)

// Example:
$.number.calc(12, 4, 'add')
//=> 16

$.number.calc(12, 4, 'subtract')
//=> 8

$.number.calc(12, 4, 'multiply')
//=> 48

$.number.calc(12, 4, 'divide')
//=> 3

$.number.calc(12, 4, 'remainder')
//=> 0

$.number.calc(12, 4, 'exponent')
//=> 20736

To calculate remainder, we must provide the left operand greater or the same as right operant, otherwise if the number of right operand bigger than the left operand, the result will be the left operand number. If the same, it mean the result will be 0 or -0, but if the left operand number bigger, the right operand will be calculate it until match the number of left operand and the left over of that number wil be the result or the number of left operand will be subtract by calculated right operand.

Last updated