JavaScript command line calculator
<p>I want to made calculator without buttons. 
Can you help me with function calculate?
I have two arrays, first array with numbers, and second with arithmetic operators.
In function calculate I must send one element from first array and one from second, but it dont work. In final program must give answer as number.
Can you explain me method reduce, can i send second array as a parameter?
Because in docs i find that it only sum elements.
Ill be very grateful if somebody write example of method reduce with function.
Here is my code.</p>

<pre><code>var str = ("1+1+1+1-1*3");
var reg = /(\d+\.\d+)|\d+/g;

var myArray = str.match(reg);
var reg1 = /['+','-','*',"/"]/g;
var myArray2 = str.match(reg1);

console.log(myArray);
console.log(myArray2);



var i = 0;


function calculate(prev,curr,i){
if(myArray2[i] === "+"){
    // 
    curr = parseInt(prev,10)+parseInt(curr,10);
}

    else if(myArray2[i]==='-'){
        //
    curr = prev-curr;}

    else if(myArray2[i] ==='*'){
        //
        return prev*curr;
    }

    else{
        //
        return prev/curr;
    }
    }
var finAns = myArray.reduce(calculate);
alert ("Answer = " +finAns);
</code></pre>
