title: How do I compute an array (or string) of numbers and mathematical operators
body: <p>I am making a calculator and pushing/saving all the numbers and operators clicked to an array and a string.</p>
  
  <p>I want to know which <strong>approach</strong> <strong>is the best in this case</strong>. Making a string or an array from the input <strong>OR</strong> a better approach I can't think of.</p>
  
  <p>I want to compute the array or string. The string is giving wrong answers and I don't have a clue on how I can compute the array. The demo calculator is below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function(){
    var inputArr = [];
    var inputStr = '';
    
    $('span').click(function(){
    $('#input').append($(this).text());
    //push to inputArr
     inputArr.push($(this).text());
    //add to inputStr
     inputStr += $(this).text();
    
    });
    
    //Get result
    $('.equals').click(function(){
      $('#result').text(inputArr);
      $('#result').append("&lt;br/&gt;" + parseInt(inputStr));
    });
    
    $('.clear').click(function(){
     // clear everything
    $('#input').text('');
    inputArr = [];
    inputStr = '';
    
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>span {
    background: #bbb;
    border-radius: 2px;
    margin: 5px;
    padding: .5em;
    cursor: pointer;
  }
  .equals{
    width: 30%;
    background: #bbb;
    border-radius: 2px;
    margin: 15px;
    padding: .5em;
    cursor: pointer;
    text-align: center;
    font-size: 1.5em;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;span&gt;1&lt;/span&gt;  &lt;span&gt;2&lt;/span&gt;  &lt;span&gt;3&lt;/span&gt;  &lt;span&gt;4&lt;/span&gt;  &lt;span&gt;5&lt;/span&gt; 
  &lt;br/&gt;
  &lt;br/&gt;
  
  &lt;span&gt;6&lt;/span&gt;  &lt;span&gt;7&lt;/span&gt;  &lt;span&gt;8&lt;/span&gt;  &lt;span&gt;9&lt;/span&gt;  &lt;span&gt;0&lt;/span&gt; 
  &lt;br/&gt;&lt;br/&gt;
     
  
  &lt;span&gt;+&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span class='clear'&gt;clear&lt;/span&gt;
  
  &lt;p class="equals"&gt; = &lt;/p&gt;
  
  &lt;p id="input"&gt;&lt;/p&gt;
  
  &lt;p id='result'&gt;&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I tried using <code>parseInt(inputStr)</code> but it gives wrong answers.</p>