If I try to ask for a large number (say 1 million) I run out of RAM:
$ node app.js
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
Somehow you're using O(n) RAM to do the calculation. Seems bad bro.This code is the epitome of roflscale