JavaScript – Binary Search

The following is an implementation of a binary search for arrays which gives you the ability to do fuzzy matches (default), exact matches, or specify your own comparison function: I used the following to test the normal execution of this binary function:

POW Answer – Disarm A Bomb with Water

This is the answer to last week’s Problem of the Week: Fill the 5.2 gallon bottle. Poor 4 gallons from the 5.2 bottle into to 4 gallon bottle, leaving 1.2 gallons in the 5.2 gallon bottle. Empty the 4 gallon bottle. Poor the remaining 1.2 gallons into the 4 gallon Read more…

POW – Disarm A Bomb with Water

You are police officer who just showed up to a crime scene where the instructions for disarming a bomb are left.  The bomb is sitting in front of a large fountain of water.  Also, two large bottles are near the bomb.  One bottle has a capacity of 5.2 gallons while Read more…

POW Answer – Unnamed Function #1

The answer to last week’s Problem of the Week is that the following definitions represent the factorial of the given non-negative integer: Mathematical Definition Function Definition Condition unnamed(n) = 1 if n = 0 n × unnamed(n – 1) if n > 0 JavaScript Definition Although it may have been Read more…

POW – Unnamed Function #1

This Problem of the Week involves determining the identity of a well-known mathematical function by examining the algorithm used on the input number to produce the output.  The function will only accept integers that are greater than or equal to zero. The following is the mathematical definition of the function: Function Definition Condition Read more…

Math

This is the Problem of the Week answer for this post. Part #1 Both Don and Juan and are given a task on which they must work together to complete in a timely fashion. It takes Don 75 minutes to do the job by himself. It takes Juan 60 minutes Read more…

POW – Working Together

Both Don and Juan and are given a task on which they must work together to complete in a timely fashion. It takes Don 75 minutes to do the job by himself. It takes Juan 60 minutes to do the job by himself. At their speed, how long would it Read more…

Quick JavaScript Encryption Method

Recently, I have been interested in creating a quick one-way encryption method. After playing around with a lot of different variations, I settled on the following: One nice thing about this function is the fact that you can restrict the encrypted message to a certain length. Another interesting thing is Read more…

JavaScript – Bitwise Operator Limitations

Did you know that the bitwise operators always return 32-bit (signed) integers? If you don’t believe me, test out the following examples for yourself:

Wrapping Integers In JavaScript & PostgreSQL

Recently, I had to create a PostgreSQL equivalent of the Java hashCode() function. In order to do this, I needed a way to make sure that numbers that exceed the INTEGER representation (ranging from -2^31 to 2^31-1) will be wrapped. In JavaScript, this is as simple as using the logical Read more…