The input values are stored in an array, the below loop is to calculate the final result, by looping through the array and appending the operators and numbers to a variable which is then evaluated.
privateCalculate = function () {
var total;
for(i = 0; i < init.sequence.length; i++) {
if(init.sequence[i] === "+" || init.sequence[i] === "-" ||
init.sequence[i] === "*" || init.sequence[i] === "/" ||
init.sequence[i] === "(" || init.sequence[i] === ")")
{
total += init.sequence[i];
} else {
init.sequence[i] = parseFloat(init.sequence[i]);
total += init.sequence[i];
}
}
console.log(eval(total));
//console.log((parseFloat(1)+parseFloat(2))/parseFloat(2));
},
The function produces "NaN"
init.sequenceparseFloat, your strings will be converted to ints withevalanywaytotal=init.sequence.join("")var arr = ["10","+","5","-","2","*","3"]>>> this is all you need:eval(arr.join(""))