JavaScript lacks native tail-call optimization. The trampoline pattern
solves this: instead of calling itself recursively, a function returns a
thunk (a zero-argument function). The trampoline runner calls it
repeatedly until it gets a non-function result.
Implement trampoline(fn) — a higher-order function that wraps fn and
keeps calling it as long as the result is a function.
Then implement solve(n) which computes the n-th triangular number
(1+2+…+n) using a trampolined recursive function.
Sample tests