js: recursive sum, avg, and gcd