Looking for input on creating a calculation function for my Dialogflow app without using eval() since it can be harmful. Are there any alternative methods for this purpose?
For example:
var number = 4
var number1 = 9
var operator = '+'
console.log(eval(number + operator + number1));
This is what I have so far:
function Calculation(agent){
var number = request.body.queryResult.outputContexts[0].parameters.number;
var number1 = request.body.queryResult.outputContexts[0].parameters.number1;
var operator = request.body.queryResult.outputContexts[0].parameters.calculation;
var result = (eval(number + operator + number1));
agent.add(result);
}