Playing around with recursive functions in JavaScript