Master Recursion in JavaScript