recursion-tree-visualizer icon indicating copy to clipboard operation
recursion-tree-visualizer copied to clipboard

Incorrect return values

Open PlytonRexus opened this issue 4 years ago • 0 comments

Writing this in a hurry, so cannot be sure, but I noticed that return values were wrong for the following program. (I'll update as soon as I can). Find a screenshot and the code below.

(Great tool, btw!)

function fn(n) {
  Array.prototype.size = function() {
    return this.length
  }
  
  ans = new Array(n)
  
  if(n == 0)
    return ans;
  if(n==1)
    return [0,1];
      
  ans = fn(n-1);
  for(let i = ans.size()-1;i >= 0; i--)
    ans.push(ans[i] | 1<<n-1);
  return ans;
}

image

PlytonRexus avatar Aug 18 '21 14:08 PlytonRexus