jPaq Examples

August 11th, 2011 @ 11:00:03

Compacting Arrays

The JavaScript library Prototype offers a function which basically removes all of the undefined and null values from the array. Fortunately, JavaScript 1.6 offers a function called Array.prototype.filter() which makes writing this Array.prototype.compact() function of Prototype very simple. Of course, many people are still using…
May 10th, 2011 @ 2:10:05

Flatten Arrays

One of the nice functions that is provided in Prototype is Array.prototype.flatten().  It gives you the ability to turn arrays such as [0, [1, [2, [[[3]]]]], 4] into [0, 1, 2, 3, 4] by just calling the flatten function. This may seem like a challenging process to…
May 2nd, 2011 @ 12:04:05

Cartesian Product

A few weeks ago, I came across a question about finding the cartesian product of two or more arrays in JavaScript.  The following is the code to do it, using jPaq's Array.prototype.reduce() and Array.prototype.forEach() functions: function cartesianProductOf() { return Array.prototype.reduce.call(arguments, function…
April 26th, 2011 @ 2:30:34

Finding Uniques

Let's say that you have an array of 10 integers in the range of 1 to 10.  How would you remove the duplicates?  Instead of writing a couple of loops, you could just use the uniquify() function which comes with jPaq.  Check it out: // Make "arr…
April 21st, 2011 @ 9:01:45

Alerting The PC User

If you have ever written a JScript to carry out a specific task, you may have noticed that using WScript.Echo() can be a little bland.  That is why I suggest using jPaq's alert() function.  Here is an example of how to ask a Yes or No…
April 19th, 2011 @ 7:15:50

Wildcard Expression Tester

Many people know how to write wildcard searches (or wildcard expressions), but a lot less people know how to write regular expressions.  If you are this way, perhaps using the findPattern(strPattern, strOptions) function would be useful.  An example of how to use this is illustrated in the…
April 13th, 2011 @ 9:18:25

Shading Colors

Making colors darker and lighter across browsers isn't always easy, that is, unless you are using a JavaScript library like jPaq.  Below you will find a table of the three primary colors of light and two variants of each color: 50% Lighter Primary Color 50% Darker If you…
April 9th, 2011 @ 9:24:42

Case Insensitive Sort

Have you ever had to sort an array in JavaScript?  With the built-in sort function, the task is usually pretty easy when it comes to an array of strings.  As you probably already know, the native sort function is case sensitive by default.  How do we…
April 7th, 2011 @ 2:54:46

Currying Up String Functions

You ever wonder how libraries such as jPaq and Prototype add prototype functions to different classes?  At for jPaq, it isn't by relying on the curry function.  Perhaps it should be though.  The following example shows that you can use the curry function to produce trim…
April 6th, 2011 @ 7:49:03

Reducing to the Longest Word

Enter as many words as you want in the textbox below and then press the "Get Longest Word Length" button to see how many characters the longest word has: Get Longest Word Length Basically, all I am doing is getting an array of all of the words in the textbox…
More News:  12