Who can help implement recursion for issuing change?

Hello everyone. I wrote function with recursion for issuing change. For example if num equal 85 resultArr must have : 60,20,5. But function push too many items to resultArr, who can help me?

function ckeck(arr,num){

  let resultArr=[]

function makeArr(arr,num){
      if(el<num) {
      return makeArr(arr = arr.slice(arr.indexOf(el)),num-el)


ckeck([90,60,20,10,5] , 80 )

we would love to help you, but we would really need some more infos on what your code should do and what instead it is doing.

Also, if you have trouble understaing what your code is doing, you can use a tool like http://pythontutor.com/javascript.html too look at the steps in the process

For example if ckeck([90,60,20,10,5] , 85 ), resultArr must have : 60,20,5 , function must have recursion

Easy version would look like this:

function sum(arr) {
  return arr.reduce((a, b) => a + b, 0);

function check(arr, num) {
  const [head, ...rest] = arr;

  if (head === undefined) return [];
  if (head === num) return [head];
  if (head > num) return check(rest, num);

  const out = [head].concat(check(rest, num - head));
  return sum(out) === num && out; // false will be returned if no sequence found

Proper version would require some dynamic programming and would be quite more difficult by keeping a stack of numbers checked

Thank you for example