spudly.shuoink.com

the best way to predict the future is to implement it

Entries Comments


Array.difference();

31 May, 2008 (17:00) | JavaScript | 2 comments

Here’s a prototyped method for Array that computes the symmetric difference between two arrays. It basically returns all the values that are in one or the other array but not both.
Usage:
var setA = [ 1, 2, 3, 4, 5, 6 ];
var setB = [ 4, 5, 6, 7, 8, 9, 10 ];
var diff = setA.difference( [...]

Array.complement();

31 May, 2008 (16:51) | JavaScript | No comments

Heres a method to get the relative complement of one array to another. Thus, it will return an array of everything that is in the current array but not in the array you pass in.
Usage:
var setA = [ 1, 2, 3 ];
var setB = [ 3, 4, 5 ];
var setC = setA.complement( setB ); // [...]

Array.union();

31 May, 2008 (15:36) | JavaScript | No comments

Here’s another set theory prototype for the Array object in JavaScript. This one performs a union of the two arrays.
Usage;
var setA = [ 1, 2, 3, 4, 5, 6 ];
var setB = [ 4, 5, 6, 7, 8 ];
var union = setA.union( setB ); // Now union is [ 1, 2, 3, 4, 5, 6, [...]

Array.intersection()

31 May, 2008 (14:48) | JavaScript | 1 comment

I’m sure a lot of you know what set theory is if you’re reading a programming blog. Anyway, a big part of set theory is the concept of an intersection between two sets of data. This is essentially the parts of the sets that the two have in common. Here’s an prototype for the intersection [...]