Class Index | File Index

Classes


Namespace comb.array

Utilities for Arrays
Defined in: array.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
<static>  
comb.array.cartesian(a, b)
Find the cartesian product of two arrays
<static>  
comb.array.compact(arr)
Compacts an array removing null or undefined objects from the array.
<static>  
comb.array.flatten(array)
Flatten multiple arrays into a single array
<static>  
comb.array.intersect(a, b)
Finds the intersection of arrays NOTE : this function accepts an arbitrary number of arrays
<static>  
comb.array.permutations(arr, length)
Finds all permutations of an array
<static>  
comb.array.powerSet(arr)
Finds the powerset of an array
<static>  
comb.array.removeDuplicates(array)
Removes duplicates from an array
<static>  
comb.array.rotate(array, numberOfTimes)
Rotates an array the number of specified positions
<static>  
comb.array.sum(array)
Sums all items in an array
<static>  
comb.array.toArray(o)
converts anything to an array
<static>  
comb.array.transpose(Array[Array[]])
Transposes an array of arrays
<static>  
comb.array.union(arrs)
Union a variable number of arrays together
<static>  
comb.array.valuesAt(arr, indexes)
Retrieves values at specified indexes in the array
<static>  
comb.array.zip(arrays)
Zips to arrays together
Namespace Detail
comb.array
Method Detail
<static> comb.array.cartesian(a, b)
Find the cartesian product of two arrays
comb.array.cartesian([1,2], [2,3]) => [
          [1,2],
          [1,3],
          [2,2],
          [2,3]
      ]
comb.array.cartesian([1,2], [2,3,4]) => [
          [1,2],
          [1,3],
          [1,4] ,
          [2,2],
          [2,3],
          [2,4]
      ]
comb.array.cartesian([1,2,3], [2,3,4]) => [
          [1,2],
          [1,3],
          [1,4] ,
          [2,2],
          [2,3],
          [2,4] ,
          [3,2],
          [3,3],
          [3,4]
      ]
Parameters:
{Array} a
{Array} b

<static> comb.array.compact(arr)
Compacts an array removing null or undefined objects from the array.
var x;
comb.array.compact([1,null,null,x,2]) => [1,2]
comb.array.compact([1,2]) => [1,2]
Parameters:
{Array} arr

<static> comb.array.flatten(array)
Flatten multiple arrays into a single array
comb.array.flatten([1,2], [2,3], [3,4]) => [1,2,2,3,3,4]
comb.array.flatten([1,"A"], [2,"B"], [3,"C"]) => [1,"A",2,"B",3,"C"]
Parameters:
array

<static> comb.array.intersect(a, b)
Finds the intersection of arrays NOTE : this function accepts an arbitrary number of arrays
comb.array.intersect([1,2], [2,3], [2,3,5]) => [2]
comb.array.intersect([1,2,3], [2,3,4,5], [2,3,5]) => [2,3]
comb.array.intersect([1,2,3,4], [2,3,4,5], [2,3,4,5]) => [2,3,4]
comb.array.intersect([1,2,3,4,5], [1,2,3,4,5], [1,2,3]) => [1,2,3]
comb.array.intersect([[1,2,3,4,5],[1,2,3,4,5],[1,2,3]]) => [1,2,3]
Parameters:
{Array} a
{Array} b

<static> comb.array.permutations(arr, length)
Finds all permutations of an array
var arr = [1,2,3];
comb.array.permutations(arr)    => [[ 1, 2, 3 ],[ 1, 3, 2 ],[ 2, 3, 1 ],
                                    [ 2, 1, 3 ],[ 3, 1, 2 ],[ 3, 2, 1 ]]
comb.array.permutations(arr, 2) => [[ 1, 2],[ 1, 3],[ 2, 3],[ 2, 1],[ 3, 1],[ 3, 2]]
comb.array.permutations(arr, 1) => [[1],[2],[3]]
comb.array.permutations(arr, 0) => [[]]
comb.array.permutations(arr, 4) => []
Parameters:
{Array} arr
the array to permute.
{Number} length
the number of elements to permute.

<static> comb.array.powerSet(arr)
Finds the powerset of an array
 comb.array.powerSet([1,2]) => [
          [],
          [ 1 ],
          [ 2 ],
          [ 1, 2 ]
  ]
  comb.array.powerSet([1,2,3]) => [
          [],
          [ 1 ],
          [ 2 ],
          [ 1, 2 ],
          [ 3 ],
          [ 1, 3 ],
          [ 2, 3 ],
          [ 1, 2, 3 ]
      ]
  comb.array.powerSet([1,2,3,4]) => [
          [],
          [ 1 ],
          [ 2 ],
          [ 1, 2 ],
          [ 3 ],
          [ 1, 3 ],
          [ 2, 3 ],
          [ 1, 2, 3 ],
          [ 4 ],
          [ 1, 4 ],
          [ 2, 4 ],
          [ 1, 2, 4 ],
          [ 3, 4 ],
          [ 1, 3, 4 ],
          [ 2, 3, 4 ],
          [ 1, 2, 3, 4 ]
      ]
Parameters:
{Array} arr
the array to find the powerset of

<static> comb.array.removeDuplicates(array)
Removes duplicates from an array
comb.array.removeDuplicates([1,1,1]) => [1]
comb.array.removeDuplicates([1,2,3,2]) => [1,2,3]
Parameters:
{Aray} array
the array of elements to remove duplicates from

<static> comb.array.rotate(array, numberOfTimes)
Rotates an array the number of specified positions
var arr = ["a", "b", "c", "d"];
comb.array.rotate(arr)     => ["b", "c", "d", "a"]
comb.array.rotate(arr, 2)  => ["c", "d", "a", "b"]);
comb.array.rotate(arr, 3)  => ["d", "a", "b", "c"]);
comb.array.rotate(arr, 4)  => ["a", "b", "c", "d"]);
comb.array.rotate(arr, -1) => ["d", "a", "b", "c"]);
comb.array.rotate(arr, -2) => ["c", "d", "a", "b"]);
comb.array.rotate(arr, -3) => ["b", "c", "d", "a"]);
comb.array.rotate(arr, -4) => ["a", "b", "c", "d"]);
Parameters:
{Array} array
the array of elements to remove duplicates from
{Number} numberOfTimes
the number of times to rotate the array

<static> comb.array.sum(array)
Sums all items in an array
 comb.array.sum([1,2,3]) => 6
 comb.array.sum(["A","B","C"]) => "ABC";
 var d1 = new Date(1999), d2 = new Date(2000), d3 = new Date(3000);
 comb.array.sum([d1,d2,d3]) => "Wed Dec 31 1969 18:00:01 GMT-0600 (CST)"
                             + "Wed Dec 31 1969"  18:00:02 GMT-0600 (CST)"
                             + "Wed Dec 31 1969 18:00:03 GMT-0600 (CST)"
 comb.array.sum([{},{},{}]) => "[object Object][object Object][object Object]";
Parameters:
{Number[]} array
the array of numbers to sum

<static> comb.array.toArray(o)
converts anything to an array
 comb.array.toArray({a : "b", b : "c"}) => [["a","b"], ["b","c"]];
 comb.array.toArray("a") => ["a"]
 comb.array.toArray(["a"]) =>  ["a"];
 comb.array.toArray() => [];
 comb.array.toArray("a", {a : "b"}) => ["a", ["a", "b"]];
Parameters:
o

<static> comb.array.transpose(Array[Array[]])
Transposes an array of arrays
comb.array.transpose([[1,2,3], [4,5,6]]) => [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
comb.array.transpose([[1,2], [3,4], [5,6]]) => [ [ 1, 3, 5 ], [ 2, 4, 6 ] ]
comb.array.transpose([[1], [3,4], [5,6]]) => [[1]])
Parameters:
Array[Array[]] Optional
arr Array of arrays

<static> comb.array.union(arrs)
Union a variable number of arrays together
comb.array.union(['a','b','c'], ['b','c', 'd']) => ["a", "b", "c", "d"]
comb.array.union(["a"], ["b"], ["c"], ["d"], ["c"]) => ["a", "b", "c", "d"]
Parameters:
arrs
variable number of arrays to union

<static> comb.array.valuesAt(arr, indexes)
Retrieves values at specified indexes in the array
 var arr =["a", "b", "c", "d"]
  comb.array.valuesAt(arr, 1,2,3) => ["b", "c", "d"];
  comb.array.valuesAt(arr, 1,2,3, 4) => ["b", "c", "d", null];
  comb.array.valuesAt(arr, 0,3) => ["a", "d"];
Parameters:
{Array} arr
the array to retrieve values from
indexes

<static> comb.array.zip(arrays)
Zips to arrays together
 var a = [ 4, 5, 6 ], b = [ 7, 8, 9 ]
 comb.array.zip([1], [2], [3]) => [[ 1, 2, 3 ]]);
 comb.array.zip([1,2], [2], [3]) => [[ 1, 2, 3 ],[2, null, null]]
 comb.array.zip([1,2,3], a, b) => [[1, 4, 7],[2, 5, 8],[3, 6, 9]]
 comb.array.zip([1,2], a, b) => [[1, 4, 7],[2, 5, 8]]
 comb.array.zip(a, [1,2], [8]) => [[4,1,8],[5,2,null],[6,null,null]]
Parameters:
arrays
variable number of arrays to zip together

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Oct 25 2011 13:20:05 GMT-0500 (CDT)