One to one functions in javaScript
This wraps up this week on writing more about authoring functions in javaScript, much of which had to do with writing functions in general actually rather than specifics of why they are written in javaScript alone. In one post I touched base on the topic of function domain which is a term for the full range of possibles when it comes to the range of arguments that can be passed to a function. Another post that I wrote recently was on the topic of monotonic functions which are functions that have to do with increasing return values as an argument approaches positive infinity. That is that a function is increasing monotonic if the return value stays the same or goes up as a x argument approaches positive infinity. There are a number of other terms with monotonic functions thorough that have to do with decreasing values also though.
However there is one general type of monotonic function that stands out for me and that is a strictly increasing monotonic function, which can be thought of as an example of a one to one function which stands out from other kinds of monotonic functions some of which can be many to one. So it would seem that the term monotonic refers to several kinds of functions some of which can be many to one style functions, however some such as strictly increasing monotonic functions are very much one to one. In this post I will be focusing mainly on the topic of one to one functions which interest me when it comes to the topic of making an experience point system.
1 - The basics of monotonic functions
Say I have a get y function that will return a y value and takes one argument that is called x, and in the body of this function I am just multiplying the given x value by 5. This is then a very basic example of a strictly increasing monotonic function, and on top of that it is also one to one. The reason why is because for every given x value there is a unique y value that is returned. This differs from functions that are many to one where there may be more than one value for x that will return the same y value.
|
|
2 - Creating an inverse of a one to one function
What is great about one to one functions is that it should be possible at least in most cases to create an inverse of the function. For example lets take my basic one to one example where I am just multiplying x by 5, creating an inverse of that would just involve dividing y by 5. So then I can create a get y function along with my get x function.
|
|
3 - An experience point system example
Now that I have all of the basic out of the way when it comes to one to one functions I can now start getting into some actual use case examples.
|
|
4 - Conclusion
So writing a one to one function is the first step in making an experience point system, but there is a bot more to it than just having a one to one function. Generally I would want a function where that will take an argument that represents level that will return a xp point value to get to that level.