Blog

JavaScript – Parsing A Number

If you should ever need to parse a number into an array of bits or a different base you can use the following function: var splitNumber = (function(MAX) {   for (; MAX + 1 - MAX == 1; MAX *= 2){}   return function (num, radix) {     // Validate num     num Read more…

By Chris West, ago
Blog

EcmaScript 6 – Array.of()

A function that is proposed to be added to EcmaScript 6 is Array.of(). This function will be used to create an array of the passed parameters. Since this function is available in some browsers but not in all, here is a block of code which when executed will define it Read more…

By Chris West, ago
Blog

JavaScript – Range Array Function

A cool function that exists in Python is the range function which actually creates a list of numbers within the specified range. Once again, since I love JavaScript, here a quick imitation of this function: /** * Creates a range of numbers in an array, starting at a specified number Read more…

By Chris West, ago
Blog

JavaScript – Weighted Randomization

Today I worked on a project which involved weighted randomization. In other words, I had to randomly choose an item from an array of weighted items. The items that were assigned a higher weight were to be more likely to be picked. The following is a JavaScript function that accomplishes Read more…

By Chris West, ago