title: How to pass in a function to another function with that function's arguments being passed into that function is saved?
body: <pre><code>function calc(n,func){
      let foo = [];
  
      for (let i = 1; i &lt;=n; i++) {
          foo.push(i);
  }
  foo=foo.map(func)
  return foo
  }
  
  
  function helloworld(x){
      let ans=calc(5,calcmystery)
      return ans
  
  }
  
  
  calcmystery=(n,x)=&gt;(n+x*n)/(2)
  
  
  
  </code></pre>
  <p>I have three functions here, first is calc function, helloworld, calcmystery.</p>
  <p>My calcmystery takes in two arguments and return a value based on the mathematical operation above.</p>
  <p>My calc function takes in two arguments, the n parameter is to create an array of values 1-N and the func parameter to map and transform the values in each array according to the function passed into.</p>
  <p>My helloworld function takes in one argument x, calls the calc function and return it.</p>
  <p>My problem here is, since I only have one argument x, when i call calc inside the helloworld function, the, and when  the calcmystery function inside the calc function is called, the x parameter passed into calcmystery is not the x value I passed into the hello world function. How do I fix this code, so the x value passed into is the same and always the same value passed into the helloworld function?</p>
  <pre><code>console.log(helloworld(2))
  </code></pre>
  <p>It should output</p>
  <pre><code>[1.5,3,4.5,6,7.5]
  </code></pre>
  <p>But the output is</p>
  <pre><code>[0.5,2,4.5,8,12.5]
  </code></pre>