Array2D – A Javascript Library

Javascript has a habit of getting on my nerves with its lack of 2D array support. I find myself constantly having to recreate the wheels for making and handling these arrays. This is ridiculous, so I started a library called Array2D. It provides tools for constructing, iterating, filling, and transforming 2D arrays.

var a = new Array2D(4, 4); //make a new array with initial dimensions

//store the element number in a row-major fashion
a.forEach(function(v, x, y, a) {
    a[x][y] = 1 + x + (a.x * y);
});

//reverse the first column
var c = a.getCol(0);
c.reverse();
a.setCol(0, c);

//pretty-print to the console
a.log();

While it’s not complete (lacking some of the more intensive transformations), it is in a working state, and patches are welcome.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s