(function() {
'use strict';
/**
* Javascript LINQ-like query proof of concept
* Jimmy Chandra - 16 July 2007
* Updated on 2015-02-22
*/
/*
* Quicksort implementation for JavaScript Array (based on
* http://en.literateprograms.org/Quicksort_(JavaScript)),
* modified to pass a function delegate for the comparison function.
*/
Array.prototype.swap = function(i, j) {
var a = this,
t = a[i];
a[i] = a[j];
a[j] = t;
};
function partition(a, s, e, p, l) {
var v = a[p],
t = s,
i;
a.swap(p, e - 1);
for (i = s; i < e - 1; i++) {
if (l(a[i], v)) {
a.swap(t, i);
t++;
}
}
a.swap(e - 1, t);
return t;
}
function qsort(a, s, e, l) {
var p;
if (e - 1 > s) {
p = s + Math.floor((e - s) / 2);
p = partition(a, s, e, p, l);
qsort(a, s, p, l);
qsort(a, p + 1, e, l);
}
}
Array.prototype.quicksort = function (l) {
qsort(this, 0, this.length, l);
};
/*
* JavaScript LINQ-like query engine sample implementation
*/
function _each(o, l, a) {
var r = [],
m = o.length,
i;
if (l) {
for (i = 0; i < m; i++) {
if (l(o[i])) {
a(r, o, i);
}
}
} else {
for (i = 0; i < m; i++) {
a(r, o, i);
}
}
return r;
}
function from(o) {
return new From(o);
}
function From(o) {
/*jshint validthis: true */
this.items = o;
}
From.prototype.where = function(l) {
return new Where(
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.