title: How can I pass an arithmetic operator based on a condition in JS ? Say + for 'add' and * for 'times'
body: <p>I am writing a JS program, where i have a condition to make some arithmetic operations based on the input.
  I need to add two values if i encounter the operation type as 'add' and multiply if i get 'times' as my operator value.</p>
  
  <p>I tried using basic if conditions which can solve my problem , but also gives a lot of boiler plate code. I am trying to minimise the code and optimise it more.</p>
  
  <p>Here is what i tried</p>
  
  <pre><code>if (otMethod === 'add') {
      if (method === 'add'){
          // some computation
              result = ( (num + value) + otValue);
          // some more computation 
      }
          else{
          // some computation
          result = ( (num * value) + otValue);
          // some more computation 
      }
  } else {
      if (method === 'add'){
          // some computation
              result = ( (num + value) * otValue);
          // some more computation 
      }
          else{
          // some computation
          result = ( (num * value) * otValue);
          // some more computation 
      }
  }
  </code></pre>
  
  <p>In this , i had to change the OT calculation based on <code>otMethod</code> and had to do arithmetic operation over num based on method <code>value</code>. </p>
  
  <p>What my question is , can we dynamically pass the operator itself based on the condition of <code>method</code> and <code>otMethod</code>, so i can reduce the number of if conditions.
  Thanks in advance!</p>