title: Get closest number of an array , but store the closest inside proxy array until no target number left (negative target number accepted)
body: <p>the same as <a href="https://stackoverflow.com/questions/54554384/get-closest-but-higher-number-in-an-array">Get closest (but higher) number in an array</a> answer
  but the result is array , and would stop iterating when the target number is zero</p>
  <p>example of my undone javascript script</p>
  <pre class="lang-js prettyprint-override"><code>const counts = [4, 9, 15, 6, 2];
  var goal = 122;
  var proxyArray = [];
  
  function closest(arr, goal){
    if (goal &gt;= 0) {
      return arr.reduce(function(done,curr){
        if(Math.abs(curr - goal) &lt; Math.abs(done - goal)){
          goal = goal - curr;
          proxyArray.push(curr);
        }
  
        return proxyArray;
      }, []);
    } else {
      return proxyArray;
    }
  }
  const output = closest(counts, goal);
  
  console.log(proxyArray);
  </code></pre>
  <p>Expected result :</p>
  <pre><code>[4,9, ...] //until the total worth equal or above (but closest) to 122 (goal/left)
  </code></pre>
  <p>but got unexpected result.</p>
  <p>this is just an example, in real development i was using the same great numbers so callstack problems is not really a big problem.</p>
  <p>NOTE : help me sensei</p>