I think the bug is in the definition of the lambda function. It uses x + i for every function that it stores. This will mean that i is a constant value for each function and will return the same result regardless of its position in the function array that is created.
I think the authors intention was to have the function return a result thats dynamic to what position is in the array of functions that is created. I am not sure how to fix this error in JS.
If this is not satisfactory I would request a function in swift or objective-c you would like me to debug.