recursion exercises in Ruby, JavaScript