batch()

The batch linq operator returns a new linq object that contains the elements of the collection broken up into "array buckets" of the given 'size'. If the optional 'result selector' is given, then the buckets will contain the values projected by the result selector (rather than the elements, themselves).
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

// col1 = [ [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12] ]
var col1 = $linq(arr).batch(5).toArray();

// col2 = [ [11, 22, 33, 44], [55, 66, 77, 88], [99, 110, 121, 132] ]
var col2 = $linq(arr).batch(4, "x => x * 10 + x").toArray();

Last edited Sep 25, 2012 at 5:40 AM by battousai999, version 1