Blog

JavaScript – Date Difference Function

A few months ago I wrote a blog post about extensions to the Date.prototype. That post provided ways to add date parts and subtract date parts. Today’s post shows you how to use a generic Date.prototype.diff() function to find the difference between two dates and optionally return a string specifying Read more…

By Chris West, ago
Blog

JavaScript – Degree & Radian Conversion

Two very simple operations that you may have to deal with if writing a JavaScript that deals with trigonometry are Math.degrees() and Math.radians(). These function can be easily defined as follows: The name of these functions indicates the end result. Using the above definitions, you could run code such as Read more…

By Chris West, ago
Blog

JavaScript – Rounding with Precision

One of the things that bothers me about the native rounding functions is the fact that there is no way to specify precision. If this is something that you need to do you can use the following code to define Math.$round(...), Math.$ceil(...), and Math.$floor(...): This code Makes the following functions Read more…

By Chris West, ago
Blog

JavaScript – Euclidean Algorithm

One of the things that you often have to learn early on in school after multiplication and division is how to find the GCD (Greatest Common Divisor) of two numbers. It is possible that you know the GCD as the GCF (Greatest Common Factor) or the HCF (Higest Common Factor). Read more…

By Chris West, ago