Introducing Arrayzing

I have been talking for a while now about how I would like to create an API of some sort. I want to start being a contributor to the open source community and develop some useful open source utilities.

A natural spot for open source development is in the area of web development, an area that I have recently taken a keen interest in. I currently work as a consultant to a company building clientside solutions for their servlet web app. I am also actively teaching myself Ruby and the Rails framework. If you would like to see an example of a site I am currently playing around with, hop on over to this site.

If you are going to write an API that helps with web development, you cannot go wrong with JavaScript. Every website uses JavaScript in some way or form. JavaScript is no longer an ugly semi-useful tool. It is a powerful and useful language that supports things like closures, named parameters and metaprogramming.

There are some amazing libraries being developed in the open source community for JavaScript. One that I have been using a lot lately and which I highly recommend is jQuery. I talked a little bit about jQuery in my last post and gave a little bit of insight into it’s capabilities, but if you are a web programmer and you haven’t checked it out yet, I implore you to do so.

Anyway, Cam and I like to get into discussions about the things we would like to accomplish as programmers and often talk about programming language semantics, features and things we would like to add. We like to bounce ideas off of each other. One of our recent discussions had me suggesting the inclusion of some sort of container class that could be defined on the fly. This could be used as a way of returning multiple values from a function and reduce the need to wrap associations in simple classes.

Our most recent discussion however dealt with a problem Cam was working on in his own side-job where he had a collection of objects and wanted to filter them in some way using JavaScript. The easiest way we could think of to do this was to iterate through each object testing to see if it matched the criteria, if it did, throw it into another collection, otherwise go to the next object. This could look something like this:

temp = ["hello", "heLlo", "jim", "jack", "hellO"]; 
var result = new Array();
var index = 0;
var re = new RegExp(/hello/i);
 
for(i=0;i<temp.length;i++) 
{
   if(temp[i].match(re))
     result[index++] = temp[i];
}

The above code would return the result = ["hello", "heLlo", "hellO"];
That is a lot of code to filter out an array. This spawned the creative process and got Cam working on a little public API that I am assisting with called Arrayzing. You can find the source here.

In order to do the equivalent operation in arrayzing, the code would be:

result = $a(temp).filter( /hello/i ).toArray();

Pretty simple and beautifully powerful. Arrayzing uses jQuery like syntax to perform array manipulations and returns the wrapped set. Additionally, all Arrayzing functions can be chained together!

If you have a moment, please check it out and give us any ideas for features!

Leave a Reply