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
Blog

JavaScript – Number.getOrdinalFor()

Now Available in YourJS When dealing with numbers, at times for presentation’s sake, we need to add ordinals to numbers. For example, instead of today is the “September 28”, you may want to say that it is the “28th of September”. I wrote the following code snippet to easily add Read more…

By Chris West, ago
Blog

JavaScript – Date.prototype.format()

Sometimes you write code that you wish you could totally rework. That is how I feel about jPaq’s Date.prototype.format(). The real issue I have with it is that the metacharacters are not intuitive. Therefore, I decided to write a new version of this function which is more intuitive. The following Read more…

By Chris West, ago
Blog

JavaScript – Date.prototype Extensions

Yesterday’s post made me want to extend the Date.prototype object a bit more. Therefore I came up with the following code: The above code defines the following prototypal functions: Date Adders Date.prototype.addYears() Date.prototype.addMonths() Date.prototype.addDays() Date.prototype.addHours() Date.prototype.addMinutes() Date.prototype.addSeconds() Date.prototype.addMilliseconds() Date Differs Date.prototype.diffYears() Date.prototype.diffMonths() Date.prototype.diffDays() Date.prototype.diffHours() Date.prototype.diffMinutes() Date.prototype.diffSeconds() Date.prototype.diffMilliseconds() Unlike the XDate Read more…

By Chris West, ago