Post History
JavaScript (Node.js), 81 bytes d=(p,i=2)=>i<p?!(p%i)||d(p,i+1):0 f=(n,a=2,p=a+1)=>d(p)?f(n,a,p+1):p-a<n?f(n,p):a Try it online! Explanation: d is a helper function that returns t...
Answer
#1: Initial revision
# [JavaScript (Node.js)], 81 bytes ```javascript d=(p,i=2)=>i<p?!(p%i)||d(p,i+1):0 f=(n,a=2,p=a+1)=>d(p)?f(n,a,p+1):p-a<n?f(n,p):a ``` [Try it online!][TIO-kijvydrt] Explanation: `d` is a helper function that returns true if `p` is not prime. ``` f=(n, a=2, p=a+1) => d(p)?f(n, a, p + 1) // Recurse until p is prime // p starts at a+1 so it gets the prime after a :p-a<n?f(n, p):a // If a, p doesn't work, we already computed the next prime so it's easy to recurse ``` [JavaScript (Node.js)]: https://nodejs.org [TIO-kijvydrt]: https://tio.run/##ZcpNDoIwEEDhPbdwYdKJxUj9DTJwlgmlpoa0EzGuuHtt3ZnZfu896UPL@PL8rkO0U0oWFWuPBrD3HQ8bxVsP62qL7hpoD5VDFTSh0YyUBfvcYHAFNZeFa@rCDxhaSmMMS5yn/RwfyqkG4F79k5F0lHSSdJZ0kXSVdMuUvg "JavaScript (Node.js) – Try It Online"