Skip to content

Instantly share code, notes, and snippets.

@nire0510
Created February 29, 2016 11:22
Show Gist options
  • Save nire0510/8b424b019ac40dd93712 to your computer and use it in GitHub Desktop.
Save nire0510/8b424b019ac40dd93712 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment