Updated end.js with a very lightweigth function.

No need of so much code, you can simply do it with a for-loop.