Smita Ahinave February 2016

Spliting Formula using JQuery

I have already generated formulas and stored it in database.Now,when I want to use formulas,I select one formula from autocomplete list say for example :

abc=((bbc*40%)/cbc)+52

now ,I want to split this formula and fetch bbc,cbc values from database and calculate answer.How can I split this formula and separate out operators and operands using jQuery?

Answers


Smita Ahinave February 2016

I am succeed in splitting formula by following way,

var expression = "((bbc*40%)/cbc)+52".replace(/[^A-Z]+/gi, "#").replace(/[\.]/g, "");

var operators = expression.split("#").filter(function(n){
    return n
});

for(var i = 0; i < operators.length; i++){
    console.log("Operator"+i+" :"+operators[i]);
}

May this helpful for someone...

Post Status

Asked in February 2016
Viewed 2,942 times
Voted 8
Answered 1 times

Search




Leave an answer