Writing monotonic functions in JavaScript

I have been learning more about writing functions in javascript as of late, not so much when it comes to what the options are when it comes to functions themselves in javaScript, but different styles of functions that have more to do with math in general. That is that I have a fairly solid grasp on what a function expression is compared to a function declaration, and why arrow functions are not a drop in replacement for all kinds of functions in source code. I also know a thing or two about the function prototype object and how to use methods in the function prototype like call or apply to get a function of one prototype to work with an object of another prototype. However this post is not on any of that, it is on the topic of what a monotonic function is compared to other kinds of functions that are not monotonic.

Read More

javaScript inverse functions

I have made an experience point system, It works okay, but it lacks some additional features that I would like to add that will change the curve sort of speak as well as adding other additional features that might be needed when making such a system. So as of late I have been making a few new systems, but I have found that I should maybe take a step back and work on some more basic functions before progressing on to making one or more experience point systems. I say that because I think I need to work out some things when it comes to inverse functions which is a subject that seems to come up when getting into making an experience point system, at least speaking from my experience with making experience point systems thus far, not pun intended.

Simply put when I am making an experience point system I like to have two methods that give me an unknown value when I have a known value. As you might expect I like to have a method that will return a level number when an experience point number is given, and another function that will give an experience point number when a level number is given. So in other words I want a kind of get level function, and an inverse of this get level function that would be called something like get exp. Some times when trying to make this set of functions I get stuck, and I start to think that I might be wasting time trying to do the impossible because I am trying to create an inverse function, for a function that can not be inverted.

Some times I might be working with something that is not monotonic, or even possibility a kind of one way function. That is a kind of function where there is more than one possibility for a given set of known arguments, or I have a function where it it is easy to make one function but hard if not possible at all to make the inverse of the easy to make function. So it would seem that in order for a function to be invertible it must be a kind of pure function, and also it must be monotonic so that there is never the same output for two different arguments. On top of that in some cases it might be hard to still find or make an inversion of a function, even if it might be be pure and monotonic.

Read More

js array to string and converting an array to a string in general

I have wrote a post on the subject of the to string method of an object in general before, however in todays post I think I will take a moment to write about this subject when it comes to arrays alone. The to string method of an array will work okay when it comes to an array of primitives, however it will often fall short of expectations when it comes to an array of objects. When it comes to converting a complex array of objects into a string format it is often called for to create a custom helper function, or class prototype method to do so. It is also possible to create a custom to string method for an array, and when making a custom class that makes use of an array it is general a good idea to have a to string method as part of the prototype object.

Read More

Find the index values of arrays in javaScript

When it comes to finding the index value of one element in an array in javaScript there is the array find index method that will work okay for this sort of thing. This find index array prototype method works more or less the same way as the array find method only it will return an index value, rather than the value of the element. Whe it comes to user space options such as in the lodash library there are also methods like the lodash find method that is a fairly robust way of finding something in an array, or an object in general actually.

Although the find index, and find methods might work okay in many situations there are some sort coming s with the method. For one thing the method will always return the first element from left to right rather than the other way around. Also there are some steps that should typically be taken before finding an element in an array such as sorting, and filtering the array. For the most part the find method might be a good choice when it comes to getting an element in an array that just has a single unique value, rather than situations in which I want a list of elements where the first element in the list would be a best match.

Read More

The array splice method for removing an injecting elements in an array

When it comes to writing about javaScript by itself I have not got around o writing a post on the array splice method yet when it comes to working with arrays in javaScript. Writing about this array splice method is something that I should have got out of the way a long time ago, but better late than never.

The array splice method is often confused with the array slice method, that is some what similar, but they work in very different ways. The array slice method will return a new array from a source array from a given starting and ending index value without mutating the source array from which it is called. The splice method will remove one or more elements from a starting index, and it can also be used to inject elements at that index location while I am at it. Unlike the slice method the splice method will mutate the array in place, but one thing that is similar might be the return value of the splice method as that will be a new array of the elements that are in a given index range.

Read More