src/array.js

Method add

Parameters:

  • obj must be an Array.
    (Array to receive 'arg')

  • arg can be of any type.
    (Argument to set in 'obj')

Returns an Array
(Array that was queried)

add : function ( obj, arg ) { if ( !array.contains( obj, arg ) ) { obj.push( arg ); } return obj; },

Method binIndex

Preforms a binary search on a sorted Array

Parameters:

  • obj must be an Array.
    (Array to search)

  • arg can be of any type.
    (Value to find index of)

Returns a Number
(Index of arg within obj)

binIndex : function ( obj, arg ) { var min = 0, max = obj.length - 1, idx, val; while ( min <= max ) { idx = Math.floor( ( min + max ) / 2 ); val = obj[idx]; if ( val < arg ) { min = idx + 1; } else if ( val > arg ) { max = idx - 1; } else { return idx; } } return -1; },

Method cast

Returns an Object ( NodeList, etc. ) as an Array

Parameters:

  • obj must be an Object.
    (Object to cast)

  • key must be a Boolean.
    ([Optional] Returns key or value, only applies to Objects without a length property)

Returns an Array
(Object as an Array)

cast : function () { if ( server || ( !client.ie || client.version > 8 ) ) { return function ( obj, key ) { key = ( key === true ); var o = []; if ( !isNaN( obj.length ) ) { o = slice.call( obj ); } else if ( key ) { o = array.keys( obj ); } else { utility.iterate( obj, function ( i ) { o.push( i ); }); } return o; }; } else { return function ( obj, key ) { key = ( key === true ); var o = []; if ( !isNaN( obj.length ) ) { try { o = slice.call( obj ); } catch ( e ) { utility.iterate( obj, function ( i, idx ) { if ( idx !== "length" ) { o.push( i ); } }); } } else if ( key ) { o = array.keys( obj ); } else { utility.iterate( obj, function ( i ) { o.push( i ); }); } return o; }; } },

Method chunk

Transforms an Array to a 2D Array of chunks

Parameters:

  • obj must be an Array.
    (Array to parse)

  • size must be a Number.
    (Chunk size ( integer ))

Returns an Array
(Chunked Array)

chunk : function ( obj, size ) { var result = [], nth = number.round( ( obj.length / size ), "up" ), start = 0, i = -1; while ( ++i < nth ) { start = i * size; result.push( array.limit( obj, start, size ) ); } return result; },

Method clear

Clears an Array without destroying it

Parameters:

  • obj must be an Array.
    (Array to clear)

Returns an Array
(Cleared Array)

clear : function ( obj ) { return obj.length > 0 ? array.remove( obj, 0, obj.length ) : obj; },

Method clone

Clones an Array

Parameters:

  • obj must be an Array.
    (Array to clone)

Returns an Array
(Clone of Array)

clone : function ( obj ) { return obj.slice(); },

Method contains

Determines if obj contains arg

Parameters:

  • obj must be an Array.
    (Array to search)

  • arg can be of any type.
    (Value to look for)

Returns a Boolean
(True if found, false if not)

contains : function ( obj, arg ) { return ( array.index( obj, arg ) > -1 ); },

Method collect

Creates a new Array of the result of fn executed against every index of obj

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • fn must be a Function.
    (Function to execute against indices)

Returns an Array
(New Array)

collect : function ( obj, fn ) { var result = []; array.each( obj, function ( i ) { result.push( fn( i ) ); }); return result; },

Method compact

Compacts a Array by removing null or undefined indices

Parameters:

  • obj must be an Array.
    (Array to compact)

  • diff must be a Boolean.
    (Indicates to return resulting Array only if there's a difference)

Returns an Array
(Compacted copy of obj, or null ( if diff is passed & no diff is found ))

compact : function ( obj, diff ) { var result = []; result = obj.filter( function ( i ) { return !regex.null_undefined.test( i ); }); return !diff ? result : ( result.length < obj.length ? result : null ); },

Method count

Counts value in obj

Parameters:

  • obj must be an Array.
    (Array to search)

  • value can be of any type.
    (Value to compare)

Returns an Array
(Array of counts)

count : function ( obj, value ) { return obj.filter( function ( i ) { return ( i === value ); }).length; },

Method diff

Finds the difference between array1 and array2

Parameters:

  • array1 must be an Array.
    (Source Array)

  • array2 must be an Array.
    (Comparison Array)

Returns an Array
(Array of the differences)

diff : function ( array1, array2 ) { var result = []; array.each( array1, function ( i ) { if ( !array.contains( array2, i ) ) { array.add( result, i ); } }); array.each( array2, function ( i ) { if ( !array.contains( array1, i ) ) { array.add( result, i ); } }); return result; },

Method each

Iterates obj and executes fn Parameters for fn are 'value', 'index'

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • fn must be a Function.
    (Function to execute on index values)

  • async must be a Boolean.
    ([Optional] Asynchronous iteration)

  • size must be a Number.
    ([Optional] Batch size for async iteration, default is 10)

Returns an Array
(Array)

each : function ( obj, fn, async, size ) { var nth = obj.length, i, offset; if ( async !== true ) { for ( i = 0; i < nth; i++ ) { if ( fn.call( obj, obj[i], i ) === false ) { break; } } } else { size = size || 10; offset = 0; if ( size > nth ) { size = nth; } utility.repeat( function () { var i = 0, idx; for ( i = 0; i < size; i++ ) { idx = i + offset; if ( idx === nth || fn.call( obj, obj[idx], idx ) === false ) { return false; } } offset += size; if ( offset >= nth ) { return false; } }, undefined, undefined, false ); } return obj; },

Method empty

Determines if an Array is empty

Parameters:

  • obj must be an Array.
    (Array to inspect)

Returns a Boolean
(true if there's no indices)

empty : function ( obj ) { return ( obj.length === 0 ); },

Method equal

Determines if a is equal to b

Parameters:

  • a must be an Array.
    (Array to compare)

  • b must be an Array.
    (Array to compare)

Returns a Boolean
(true if the Arrays match)

equal : function ( a, b ) { return ( json.encode( a ) === json.encode( b ) ); },

Method fib

Fibonacci generator

Parameters:

  • arg must be a Number.
    ([Optional] Amount of numbers to generate, default is 100)

Returns an Array
(Array of numbers)

fib : function ( arg ) { var result = [1, 1], first = result[0], second = result[1], sum;

Subtracting 1 to account for first & second

arg = ( arg || 100 ) - 1; if ( isNaN( arg ) || arg < 2 ) { throw new Error( label.error.invalidArguments ); } while ( --arg ) { sum = first + second; first = second; second = sum; result.push( sum ); } return result; },

Method fill

Fills obj with the evalution of arg, optionally from start to offset

Parameters:

  • obj must be an Array.
    (Array to fill)

  • arg can be of any type.
    (String, Number of Function to fill with)

  • start must be a Number.
    ([Optional] Index to begin filling at)

  • end must be a Number.
    ([Optional] Offset from start to stop filling at)

Returns an Array
(Filled Array)

fill : function ( obj, arg, start, offset ) { var fn = typeof arg === "function", l = obj.length, i = !isNaN( start ) ? start : 0, nth = !isNaN( offset ) ? i + offset : l - 1; if ( nth > ( l - 1) ) { nth = l - 1; } while ( i <= nth ) { obj[i] = fn ? arg( obj[i] ) : arg; i++; } return obj; },

Method first

Returns the first Array node

Parameters:

  • obj must be an Array.
    (The array)

Returns a Mixed
(The first node of the array)

first : function ( obj ) { return obj[0]; },

Method flat

Flattens a 2D Array

Parameters:

  • obj must be an Array.
    (2D Array to flatten)

Returns an Array
(Flatten Array)

flat : function ( obj ) { var result = []; result = obj.reduce( function ( a, b ) { return a.concat( b ); }, result ); return result; },

Method fromObject

Creates a 2D Array from an Object

Parameters:

  • obj must be an Object.
    (Object to convert)

Returns an Array
(2D Array)

fromObject : function ( obj ) { return array.mingle( array.keys( obj ), array.cast( obj ) ); },

Method index

Facade to indexOf for shorter syntax

Parameters:

  • obj must be an Array.
    (Array to search)

  • arg can be of any type.
    (Value to find index of)

Returns a Number
(The position of arg in instance)

index : function ( obj, arg ) { return obj.indexOf( arg ); },

Method indexed

Returns an Associative Array as an Indexed Array

Parameters:

  • obj must be an Array.
    (Array to index)

Returns an Array
(Indexed Array)

indexed : function ( obj ) { var indexed = []; utility.iterate( obj, function ( v ) { indexed.push( v ); }); return indexed; },

Method intersect

Finds the intersections between array1 and array2

Parameters:

  • array1 must be an Array.
    (Source Array)

  • array2 must be an Array.
    (Comparison Array)

Returns an Array
(Array of the intersections)

intersect : function ( array1, array2 ) { var a = array1.length > array2.length ? array1 : array2, b = ( a === array1 ? array2 : array1 ); return a.filter( function ( key ) { return array.contains( b, key ); }); },

Method keepIf

Keeps every element of obj for which fn evaluates to true

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • fn must be a Function.
    (Function to test indices against)

Returns an Array
(Array)

keepIf : function ( obj, fn ) { if ( typeof fn !== "function" ) { throw new Error( label.error.invalidArguments ); } var result = [], remove = []; result = obj.filter( fn ); remove = array.diff( obj, result ); array.each( remove, function ( i ) { array.remove( obj, array.index( obj, i ) ); }); return obj; },

Method sort

Sorts an Array based on key values, like an SQL ORDER BY clause

Parameters:

  • obj must be an Array.
    (Array to sort)

  • query must be a String.
    (Sort query, e.g. "name, age desc, country")

  • sub must be a String.
    ([Optional] Key which holds data, e.g. "{data: {}}" = "data")

Returns an Array
(Sorted Array)

keySort : function ( obj, query, sub ) { query = query.replace( /\s*asc/ig, "" ).replace( /\s*desc/ig, " desc" ); var queries = string.explode( query ).map( function ( i ) { return i.split( " " ); }), sorts = []; if ( sub && sub !== "" ) { sub = "." + sub; } else { sub = ""; } array.each( queries, function ( i ) { var desc = i[1] === "desc"; if ( !desc ) { sorts.push( "if ( a" + sub + "[\"" + i[0] + "\"] < b" + sub + "[\"" + i[0] + "\"] ) return -1;" ); sorts.push( "if ( a" + sub + "[\"" + i[0] + "\"] > b" + sub + "[\"" + i[0] + "\"] ) return 1;" ); } else { sorts.push( "if ( a" + sub + "[\"" + i[0] + "\"] < b" + sub + "[\"" + i[0] + "\"] ) return 1;" ); sorts.push( "if ( a" + sub + "[\"" + i[0] + "\"] > b" + sub + "[\"" + i[0] + "\"] ) return -1;" ); } }); sorts.push( "else return 0;" ); return obj.sort( new Function( "a", "b", sorts.join( "\n" ) ) ); },

Method keys

Returns the keys in an "Associative Array"

Parameters:

  • obj can be of any type.
    (Array or Object to extract keys from)

Returns an Array
(Array of the keys)

keys : function () { if ( typeof Object.keys === "function" ) { return function ( obj ) { return Object.keys( obj ); }; } else { return function ( obj ) { var keys = []; utility.iterate( obj, function ( v, k ) { keys.push( k ); }); return keys; }; } }(),

Method last

Returns the last index of the Array

Parameters:

  • obj must be an Array.
    (Array)

  • arg must be a Number.
    ([Optional] Negative offset from last index to return)

Returns a Mixed
(Last index( s ) of Array)

last : function ( obj, arg ) { var n = obj.length - 1; if ( arg >= ( n + 1 ) ) { return obj; } else if ( isNaN( arg ) || arg === 1 ) { return obj[n]; } else { return array.limit( obj, ( n - ( --arg ) ), n ); } },

Method limit

Returns a limited range of indices from the Array

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • start must be a Number.
    (Starting index)

  • offset must be a Number.
    (Number of indices to return)

Returns an Array
(Array of indices)

limit : function ( obj, start, offset ) { var result = [], i = start - 1, nth = start + offset, max = obj.length; if ( max > 0 ) { while ( ++i < nth && i < max ) { result.push( obj[i] ); } } return result; },

Method max

Finds the maximum value in an Array

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Mixed
(Number, String, etc.)

max : function ( obj ) { return array.last( obj.sort( array.sort ) ); },

Method mean

Finds the mean of an Array ( of numbers )

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Number
(Mean of the Array ( float or integer ))

mean : function ( obj ) { return obj.length > 0 ? ( array.sum( obj ) / obj.length ) : undefined; },

Method median

Finds the median value of an Array ( of numbers )

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Number
(Median number of the Array ( float or integer ))

median : function ( obj ) { var nth = obj.length, mid = number.round( nth / 2, "down" ), sorted = obj.sort( array.sort ); return number.odd( nth ) ? sorted[mid] : ( ( sorted[mid - 1] + sorted[mid] ) / 2 ); },

Method merge

Merges arg into obj, excluding duplicate indices

Parameters:

  • obj must be an Array.
    (Array to receive indices)

  • arg must be an Array.
    (Array to merge)

Returns an Array
(obj)

merge : function ( obj, arg ) { array.each( arg, function ( i ) { array.add( obj, i ); }); return obj; },

Method min

Finds the minimum value in an Array

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Mixed
(Number, String, etc.)

min : function ( obj ) { return obj.sort( array.sort )[0]; },

Method mingle

Mingles Arrays and returns a 2D Array

Parameters:

  • obj1 must be an Array.
    (Array to mingle)

  • obj2 must be an Array.
    (Array to mingle)

Returns an Array
(2D Array)

mingle : function ( obj1, obj2 ) { var result; result = obj1.map( function ( i, idx ) { return [i, obj2[idx]]; }); return result; },

Method mode

Finds the mode value of an Array

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Mixed
(Mode value of the Array)

mode : function ( obj ) { var values = {}, count = 0, nth = 0, mode = [], result;

Counting values

array.each( obj, function ( i ) { if ( !isNaN( values[i] ) ) { values[i]++; } else { values[i] = 1; } });

Finding the highest occurring count

count = array.max( array.cast( values ) );

Finding values that match the count

utility.iterate( values, function ( v, k ) { if ( v === count ) { mode.push( number.parse( k ) ); } });

Determining the result

nth = mode.length; if ( nth > 0 ) { result = nth === 1 ? mode[0] : mode; } return result; },

Method percents

Creates an Array of percentages from an Array of Numbers (ints/floats)

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • precision must be a Number.
    ([Optional] Rounding precision)

  • total must be a Number.
    ([Optional] Value to compare against)

Returns an Array
(Array of percents)

percents : function ( obj, precision, total ) { var result = [], custom = false, last, padding, sum; precision = precision || 0; if ( total === undefined ) { total = array.sum( obj ); } else { custom = true; } array.each( obj, function ( i ) { result.push( number.parse( ( ( i / total ) * 100 ).toFixed( precision ) ) ); } );

Dealing with the awesomeness of JavaScript "integers"

if ( !custom ) { sum = array.sum( result ); if ( sum < 100 ) { padding = number.parse( number.diff( sum, 100 ).toFixed( precision ) ); last = array.last( result ) + padding; result[result.length - 1] = last; } else if ( sum > 100 ) { padding = number.parse( number.diff( sum, 100 ).toFixed( precision ) ); last = number.parse( ( array.last( result ) - padding ).toFixed( precision ) ); result[result.length - 1] = last; } } return result; },

Method range

Finds the range of the Array ( of numbers ) values

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Number
(Range of the array ( float or integer ))

range : function ( obj ) { return array.max( obj ) - array.min( obj ); },

Method rassoc

Searches a 2D Array obj for the first match of arg as a second index

Parameters:

  • obj must be an Array.
    (2D Array to search)

  • arg can be of any type.
    (Primitive to find)

Returns a Mixed
(Array or undefined)

rassoc : function ( obj, arg ) { var result; array.each( obj, function ( i, idx ) { if ( i[1] === arg ) { result = obj[idx]; return false; } }); return result; },

Method reject

Returns Array containing the items in obj for which fn() is not true

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • fn must be a Function.
    (Function to execute against obj indices)

Returns an Array
(Array of indices which fn() is not true)

reject : function ( obj, fn ) { return array.diff( obj, obj.filter( fn ) ); },

Method replace

Replaces the contents of obj with arg

Parameters:

  • obj must be an Array.
    (Array to modify)

  • arg must be an Array.
    (Array to become obj)

Returns an Array
(New version of obj)

replace : function ( obj, arg ) { array.remove( obj, 0, obj.length ); array.each( arg, function ( i ) { obj.push( i ); }); return obj; },

Method remove

Removes indices from an Array without recreating it

Parameters:

  • obj must be an Array.
    (Array to remove from)

  • start can be of any type.
    (Starting index, or value to find within obj)

  • end must be a Number.
    ([Optional] Ending index)

Returns an Array
(Modified Array)

remove : function ( obj, start, end ) { if ( isNaN( start ) ) { start = obj.index( start ); if ( start === -1 ) { return obj; } } else { start = start || 0; } var length = obj.length, remaining = obj.slice( ( end || start ) + 1 || length ); obj.length = start < 0 ? ( length + start ) : start; obj.push.apply( obj, remaining ); return obj; },

Method removeIf

Deletes every element of obj for which fn evaluates to true

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • fn must be a Function.
    (Function to test indices against)

Returns an Array
(Array)

removeIf : function ( obj, fn ) { var remove; if ( typeof fn !== "function" ) { throw new Error( label.error.invalidArguments ); } remove = obj.filter( fn ); array.each( remove, function ( i ) { array.remove( obj, array.index ( obj, i ) ); }); return obj; },

Method removeWhile

Deletes elements of obj until fn evaluates to false

Parameters:

  • obj must be an Array.
    (Array to iterate)

  • fn must be a Function.
    (Function to test indices against)

Returns an Array
(Array)

removeWhile : function ( obj, fn ) { if ( typeof fn !== "function" ) { throw new Error( label.error.invalidArguments ); } var remove = []; array.each( obj, function ( i ) { if ( fn( i ) !== false ) { remove.push( i ); } else { return false; } }); array.each( remove, function ( i ) { array.remove( obj, array.index( obj, i) ); }); return obj; },

Method rest

Returns the "rest" of obj from arg

Parameters:

  • obj must be an Array.
    (Array to parse)

  • arg must be a Number.
    ([Optional] Start position of subset of obj ( positive number only ))

Returns an Array
(Array of a subset of obj)

rest : function ( obj, arg ) { arg = arg || 1; if ( arg < 1 ) { arg = 1; } return array.limit( obj, arg, obj.length ); },

Method rindex

Finds the last index of arg in obj

Parameters:

  • obj must be an Array.
    (Array to search)

  • arg can be of any type.
    (Primitive to find)

Returns a Mixed
(Index or undefined)

rindex : function ( obj, arg ) { var result = -1; array.each( obj, function ( i, idx ) { if ( i === arg ) { result = idx; } }); return result; },

Method rotate

Returns new Array with arg moved to the first index

Parameters:

  • obj must be an Array.
    (Array to rotate)

  • arg must be a Number.
    (Index to become the first index, if negative the rotation is in the opposite direction)

Returns an Array
(Newly rotated Array)

rotate : function ( obj, arg ) { var nth = obj.length, result; if ( arg === 0 ) { result = obj; } else { if ( arg < 0 ) { arg += nth; } else { arg--; } result = array.limit( obj, arg, nth ); result = result.concat( array.limit( obj, 0, arg ) ); } return result; },

Method series

Generates a series Array

Parameters:

  • start must be a Number.
    (Start value the series)

  • end must be a Number.
    ([Optional] The end of the series)

  • offset must be a Number.
    ([Optional] Offset for indices, default is 1)

Returns an Array
(Array of new series)

series : function ( start, end, offset ) { start = start || 0; end = end || start; offset = offset || 1; var result = [], n = -1, nth = Math.max( 0, Math.ceil( ( end - start ) / offset ) ); while ( ++n < nth ) { result[n] = start; start += offset; } return result; },

Method split

Splits an Array by divisor

Parameters:

  • obj must be an Array.
    (Array to parse)

  • divisor must be a Number.
    (Integer to divide the Array by)

Returns an Array
(Split Array)

split : function ( obj, divisor ) { var result = [], total = obj.length, nth = Math.ceil( total / divisor ), low = Math.floor( total / divisor ), lower = Math.ceil( total / nth ), lowered = false, start = 0, i = -1;

Finding the fold

if ( number.diff( total, ( divisor * nth ) ) > nth ) { lower = total - ( low * divisor ) + low - 1; } else if ( total % divisor > 0 && lower * nth >= total ) { lower--; } while ( ++i < divisor ) { if ( i > 0 ) { start = start + nth; } if ( !lowered && lower < divisor && i === lower ) { --nth; lowered = true; } result.push( array.limit( obj, start, nth ) ); } return result; },

Method sort

Sorts the Array by parsing values

Parameters:

  • a can be of any type.
    (Argument to compare)

  • b can be of any type.
    (Argument to compare)

Returns a Number
(Number indicating sort order)

sort : function ( a, b ) { var types = {a: typeof a, b: typeof b}, c, d, result; if ( types.a === "number" && types.b === "number" ) { result = a - b; } else { c = a.toString(); d = b.toString(); if ( c < d ) { result = -1; } else if ( c > d ) { result = 1; } else if ( types.a === types.b ) { result = 0; } else if ( types.a === "boolean" ) { result = -1; } else { result = 1; } } return result; },

Method sorted

Sorts obj using array.sort

Parameters:

  • obj must be an Array.
    (Array to sort)

Returns an Array
(Sorted Array)

sorted : function ( obj ) { return obj.sort( array.sort ); },

Method stddev

Finds the standard deviation of an Array ( of numbers )

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Number
(Standard deviation of the Array ( float or integer ))

stddev : function ( obj ) { return Math.sqrt( array.variance( obj ) ); },

Method sum

Gets the summation of an Array of numbers

Parameters:

  • obj must be an Array.
    (Array to sum)

Returns a Number
(Summation of Array)

sum : function ( obj ) { var result = 0; if ( obj.length > 0 ) { result = obj.reduce( function ( prev, cur ) { return prev + cur; }); } return result; },

Method take

Takes the first arg indices from obj

Parameters:

  • obj must be an Array.
    (Array to parse)

  • arg must be a Number.
    (Offset from 0 to return)

Returns an Array
(Subset of obj)

take : function ( obj, arg ) { return array.limit( obj, 0, arg ); },

Method total

Gets the total keys in an Array

Parameters:

  • obj must be an Array.
    (Array to find the length of)

Returns a Number
(Number of keys in Array)

total : function ( obj ) { return array.indexed( obj ).length; },

Method toObject

Casts an Array to Object

Parameters:

  • ar must be an Array.
    (Array to transform)

Returns an Object
(New object)

toObject : function ( ar ) { var obj = {}, i = ar.length; while ( i-- ) { obj[i.toString()] = ar[i]; } return obj; },

Method unique

Returns an Array of unique indices of obj

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns an Array
(Array of unique indices)

unique : function ( obj ) { var result = []; array.each( obj, function ( i ) { array.add( result, i ); }); return result; },

Method variance

Finds the variance of an Array ( of numbers )

Parameters:

  • obj must be an Array.
    (Array to parse)

Returns a Number
(Variance of the Array ( float or integer ))

variance : function ( obj ) { var nth = obj.length, n = 0, mean; if ( nth > 0 ) { mean = array.mean( obj ); array.each( obj, function ( i ) { n += math.sqr( i - mean ); } ); return n / nth; } else { return n; } },

Method zip

Converts any arguments to Arrays, then merges elements of obj with corresponding elements from each argument

Parameters:

  • obj must be an Array.
    (Array to transform)

  • args can be of any type.
    (Argument instance or Array to merge)

Returns an Array
(Array)

zip : function ( obj, args ) { var result = [];

Preparing args

if ( !(args instanceof Array) ) { args = typeof args === "object" ? array.cast( args ) : [args]; } array.each( args, function ( i, idx ) { if ( !( i instanceof Array ) ) { this[idx] = [i]; } });

Building result Array

array.each( obj, function ( i, idx ) { result[idx] = [i]; array.each( args, function ( x ) { result[idx].push( x[idx] || null ); }); }); return result; } };