Way to go from recursion to iteration
Usually, I replace a recursive algorithm by an iterative algorithm by pushing the parameters that would normally be passed to the recursive function onto a stack. In fact, you are replacing the program stack by one of your own. var stack = []; stack.push(firstObject); // while not empty while (stack.length) { // Pop off end … Read more