/Linq

IEnumerable Implementation for JavaScript.

Primary LanguageJavaScript

Linq

IEnumerable Implementation for JavaScript. I based this on Microsoft's IEnunermable documentation. I've found this really handy when doing back-end programming in C# and decided I'd like something like this for JavaScript. It doesn't use C#'s implemetation of lambda functions so developers still need to have some understanding of JavaScript's functions.

Implementation Examples

How thins work and examples. All functions should be function( element ) { [some execution] return [some result];} unless otherwise specified.
Variables in brackets are optional.
To use this, create an array and put it through the Linq function. var linqObj = Linq( AnArray ) ;

Any( [fn] ) - Boolean

Returns true or false based on whether any element returns true for the function fn.

Average( [fn] ) - Number

Calculates the average of the array. If there a function is passed, it uses the value returned by the function to calculate the average.

Concat( array ) - Linq

Takes an array and concatenates it to the end of the Linq object's array and returns a new Linq object.

Contains( object[, compareFn] ) - Boolean

Contains( object, [fn( element, object ) ] ) - Boolean

Distinct( [fn] ) - Linq

ElementAt( number ) - Object

ElementAtOrDefault( number ) - Object

Except( linq[, fn] ) - Linq

First( [fn] ) - Object

FirstOrDefault( [fn] ) - Object

Intersect( [fn] ) - Linq

Join( array, outerSelectorFn, innerSelectorFn, resultFn<innerElement, outerElement>[, compareFn] ) - Linq

Last( [fn] ) - Object

LastOrDefault( [fn] ) - Object

Max( [fn] ) - Number

Min( [fn] ) - Number

OrderBy( [fn] ) - Linq

Reverse( ) - Linq

Select( [fn] ) - Linq

SelectMany( [fn] ) - Linq

Single( [fn] ) - Object

SingleOrDefault( [fn] ) - Object

Skip( number ) - Linq

SkipWhile( [fn] ) - Linq

Sum( [fn] ) - Number

Take( number )

TakeWhile( [fn] ) - Linq

Union( array, [fn( element, inputArrayElement ) ] ) - Linq

Where( [fn] ) - Linq