Math pow in javaScript

The Math pow method is what can be used in javaScript to create a number that is a power from a base and an exponent, also know as Exponentiation. The use of this will come up often when working out expressions for things like curves, finding the distance between two points, working out a formula for leveling up a character in a game, and much more. There are many other Math methods that are often used in conjunction with Math.pow, such as Math.sqrt to create all kinds of useful expressions that are often used in creating pure functions that make up a useful module for kind of general task or another.

So then in this post I will be going over some basic examples of the Math.pow method of course, but from there I will also be getting into some other examples that I find myself using all the time in various projects. That is some usual suspects of sorts when it comes to the use of the Math.pow method in expressions and pure functions. However the focal point here will be the Math pow method and a few other things of interest the revolve around the method as I see it.

Read More

Canvas Curve basics

So in canvas curves are a topic that one will just get into at one point or another, it just seems to be something that comes naturally when staring to play around with canavs elements and javaScript. There are 2d drawing API methods such as the canvas arc method and well as some others that can be used to draw more complex curves such as the bezier curve to method. However these methods do not help when it comes to pulling the state of something away from the process of rendering such a state.

When it comes to really getting into curves, and starting to have a deep understand and appreciation for drawing curves in canvas, I feel as though I need to do something that involves making methods that create point collections.

Read More

lodash eq method, Object.is, SameValueZero, equality, and identity

So there is the lodash eq method that is one way of finding out the same value zero result of two values. However what is same value zero, and is it all that hard to get the same result in native javaScript itself these days?

Well in ECMA2015 spec javaScript the Object.is static method was introduced that does indeed do the same thing as the lodash eq method, only not the exact same way, as the Object is method goes by a slightly different standard that handles zero and negative zero a little differently. So then there is the Same Value standard, used by the Object is method, that will return false if positive and negative zero are compared. Then on top of the Same value standard there is also the Same Value Zero standard that will return true which is what the lodahs eq method uses.

So if this is the only thing that you care about in a project, maybe a simple polyfill will do just fine and you can ditch lodash to the curb. Otherwise the lodash _.eq method can do more or less the same thing if you are still keeping lodash as part of your projects stack becuase of client support concerns, or other method of interest that are not native in any javaScript spec.

Regardless of what you attitude is with lodash these days I will make this post also about Same Value Zero in general so that this is not just a post on lodash eq alone.

Read More

lodash intersection method

Time for another post on lodash this one is on the lodash intersection method. The _.intersection method will create an array of values that are in all the given arrays using the lodash _.eq method also known as same value zero for comparisons.

This is yet another kind of task that is not so hard to do with just plain old javaScript by itself these days using array prototype methods such as array some, and array filter. There is also a native method called Object is that can be used to get the same value result rather than just using equality and identity operators. However regardless if you use lodash or not this will be a post on creating arrays of intersecting values in javaScript in general so lets get to it.

Read More

The Array sort method in javaScript

In native javaScript there is the array sort method in the array prototype object, that can be used to sort the elements in place. This fact that the array sort mutates an array in place might be one reason why you might want to use an alternative user space method to the array sort method, such as the lodash _.sortBy method in lodash. This method is like array sort, but will work out of the box with object collections in general beyond that of arrays. In addition it will not mutate the object in place like array sort does, but create and return a new array.

However in this post I will be sticking to plain old native javaScript by itself, and looking into just working with what there is to work with in the array prototype, and with other native javaScript features without bothering with a user space library of some kind. When it comes to the problem of the array sort method mutating the array in place I can just make use of one of the many options for copying an array to make a shallow or deep clone of a source array first if I do not want to mutate the array in place. After that I just need to learn how to create sort methods for the array sort method that might change a little from one situation to the next.

Read More