<pre> function getResult(exp) {
exp = '1 * ' + exp;
var parts = exp.split(' ');
var result, num = [], exp = []; var formu = [];
for (var i = 0; i < parts.length; i++) {
var item = parts[i].trim();
if (isNaN(item))
exp.push(item);
else
num.push(item);
}
for (var i = 0; i < num.length + 1; i++) {
var expr = exp[i - 1] == undefined ? '' : exp[i - 1];
var numr = num[i] == undefined ? '' : num[i];
var str = expr + numr;
if (i == 0)
str = '1'
result = result == undefined ? '' : result;
result = eval(result + str);
}
return result;
}
console.log(getResult( "10 * 20 / 30 - 60 + 2"))