nire0510
2/29/2016 - 11:22 AM

Ember helper: performs arithmetic operations

Ember helper: performs arithmetic operations

import Ember from 'ember';

export function math([numOperand1, strOperator, numOperand2]/*, hash*/) {
  numOperand1 = parseFloat(numOperand1);
  numOperand2 = parseFloat(numOperand2);

  return {
    '+': numOperand1 + numOperand2,
    '-': numOperand1 - numOperand2,
    '*': numOperand1 * numOperand2,
    '/': numOperand1 / numOperand2,
    '%': numOperand1 % numOperand2,
    '^': numOperand1 ^ numOperand2
  }[strOperator];
}

export default Ember.Helper.helper(math);