JS solution using function closures

No need to name 'n', just return the function expression.