I was curious on how level was determined for games and I found an awesome article about it by Jake Lee.
But one important thing was not explained in this article, how is it implemented in JavaScript?!
He has provided implementations in a Google Sheet and Github Gist though. So that may be your preferred method.