take()

The take linq operator returns a new linq object that contains the first "count" number of elements from the collection. If "count" is greater than the number of elements in the collection, then all of the elements in the collection will be contained in the results.
var arr = [1, 2, 3, 4, 5];

// col1 = [1, 2, 3, 4]
var col1 = $linq(arr).take(4).toArray();

// col2 = [1, 2, 3, 4, 5]
var col2 = $linq(arr).take(100).toArray();

takeWhile()

The takeWhile linq operator returns a new linq object that contains the largest set of elements taken from the beginning of the collection that all statisfy the given "predicate" function. In other words, elements are chosen from the beginning of the collection until an element is encountered that does not satisfy the predicate.
var arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5];

// col = [1, 2, 3, 4]
var col = $linq(arr).takeWhile("x => x < 5").toArray();

Last edited Sep 20, 2012 at 4:11 PM by battousai999, version 4