lodash some

The lodash _.some collection method can be used to test to see if just one element of an array, or key value pair of an object in general meets a given condition. In the event that just one or more puplic keys of the collection is true then the return value for the lodash some method will in turn also be true. There is another collection method known as _.every that works in a similar way to that of the _.some method but will only return true when all elements of a collection meet a given condition rather than just one.

In this post I will be going over some simple examples of both the lodash some and every methods. Also there are as some ways of doing the same thing so with just plain old vanilla js also that are worth covering. There are native javaScript equivalents for both the some and every methods although these are array prototype methods rather than collection methods. Still it is not to hard to just go with using those and count these lodash methods as just yet another example of a kind of methods that brings the relevancy of lodash into question.

Read More

lodash difference method examples

In this post I will be writing about some lodash difference method that can be used to find out what values in an array are not included on one or more additional arrays. So then as the name implies, it is a way to go about extracting the difference from an array, using one or more additional arrays as a way to known what to extract.

The comparisons are made in compliance with the Same Value Zero standard that is used in methods like that of the lodash eq method. This method of preforming comparisons works in a very similar way to that if the strict equals operator, and the native Object.is method but with subtle differences when it comes to handing NaN and rare cases with negative zero.

There are more than one method in lodash that can be used to preform this kind of task, as well as various similar tasks. There is also what there is to work with when in comes to native javaScript by itself as well.

Read More

javaScript callback functions and more

In javaScript a callback function is often used as a way to define some logic that is to execute at some point later on rather than right at the moment. For example when I go to pass a function as an argument for the add event listener function when in client side javaScript that can be thought of as a callback function. The code in the function will not run at that very moment, but it will when the event happens at which point the callback will fire, and I will have access to an event object that contains into about the event. There is then all the various built in functions in nodejs that will take a callback also when it comes to sever side javaScript.

It would also seem that a callback is also used as an umbrella term for any function that is passed as an argument to another function that is used at some point or place inside the body of that outer function that is called. So there might be some overlap here with other terms that might come up such as higher order functions, and closures.

JavaScript callbacks are often used with, or as a replacement for other options such as promises. In many javaScript projects, code examples, and so forth I often encounter callbacks now and then so it is important to know a thing or two about them. In addition it is important to be aware of the drawbacks that callbacks often present, and why other options such as promises might prove to be a better option. So i this post I will be taking a quick looks at some callback examples.

Read More

regex patterns in javaScript

When working on a javaScript project there might be a need now and then to do some text pattern matching operations with regular expressions. For example in the event that I am making some kind of parser I would need to find patterns for beginning and ending tags, or other elements of the language that I am parsing. Another thing might come up where I have a certain pattern in text that needs to be replaced with something else, and this pattern that I am looking for is not a fixed static text pattern. Regular expressions can be combined with various methods in the RegExp prototype as well as other build in prototypes, mainly the String prototype to get an array of character index values of various patterns that have to do with the nature of the language. Simply put to find Matches in a string, just for the sake of knowing if a pattern is in a string or not, or to preform some kind of replacement option, or creating some kind of result from one or more pattern matches.

So in this post I will be covering some basic examples of regular expressions in javaScript that can be used to text search and replace tasks, just for the sake of getting started with Regular expressions in javaScript. AFter that I will be getting into some of the various aspects of these patterns when it comes to the many components that form one of these patterns. After that at the bottom of this post I will be getting into at least a few basic use case examples that I have made thus far when it comes to pattern matching. So then this post should start out simple enough for those of you that are new to this sort of thing, and then progress into various other aspects of regular expressions that might prove to be more up to speed with where I might be with pattern matching in javaScript.

Read More

Math atan2 javaScript native Math object method use case examples.

The native Math.atan2 method is a 2 argument arctangent method in the javaScript Math object. The method comes in handy when I want to find the angle from one point to another in a Cartesian coordinate grid, and is then a method that would likely be used once or twice when making a library that works with angles. As of this writing I have made a library that is my take on this kind of angle library that might also be worth checking out then.

So one example of the use of the Math.atan2 is something that will come into play a lot when working out some logic for a wide range of different types of games where I am working out some kind of script where I want to find out an angle to an enemy so I know which way to rotate to, or visa versa when it comes to developing some kind of AI Script. However simply put if you have two points in a grid, and you want to know the angle from one point to the other, then the Math.atan2 method is what I would want to use to do so. So it goes without saying there are many possible applications for the atan2 method in javaSript so lets get started looking at some basic examples of Math atan2 in action, and maybe get to some additional not so basic examples while we are at it.

Read More