takeLast()

The takeLast linq operator returns a new linq object that contains the last "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 returned.
var arr = [1, 2, 3, 4, 5];

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

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

takeEvery()

The takeEvery linq operator returns a new linq object that contains every n-th element of the collection, starting with the first element of the collection.
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// col1 = [1, 3, 5, 7, 9]
var col1 = $linq(arr).takeEvery(2).toArray();

// col2 = [1, 4, 7, 10]
var col2 = $linq(arr).takeEvery(3).toArray();

// col3 = [1, 5, 9]
var col3 = $linq(arr).takeEvery(4).toArray();

// col4 = [1, 6]
var col4 = $linq(arr).takeEvery(5).toArray();

Last edited Sep 20, 2012 at 5:19 PM by battousai999, version 1