LINQ orderby
by whelkaholism
HTML
<div style="whitespace:pre-wrap" id="res">
</div>
<hr/>
<div style="whitespace:pre-wrap" id="res2">
</div>
JavaScript
if (typeof (Array.prototype.select) == 'undefined')
{
Object.defineProperty(Array.prototype, 'select', {
value: function(selector)
{
var res = [];
this.forEach && this.forEach(
function(x)
{
res.push(typeof (selector) == 'string' ? x[selector] : (typeof (selector) == 'function' ? selector(x) : x));
}
);
return res;
}
});
}
if (typeof (Array.prototype.selectMany) == 'undefined')
{
Object.defineProperty(Array.prototype, 'selectMany', {
value: function(selector)
{
var res = [];
this.forEach && this.forEach(
function(x)
{
var arr = typeof (selector) == 'string' ? x[selector] : (typeof (selector) == 'function' ? selector(x) : x);
arr.forEach && arr.forEach(function(x) { res.push(x) });
}
);
return res;
}
});
}
if (typeof (Array.prototype.where) == 'undefined')
{
Object.defineProperty(Array.prototype, 'where', {
value: function(predicate)
{
var res = [];
this.forEach && this.forEach(
function(x)
{
var match = typeof (predicate) == 'function' ? predicate(x) : x == predicate;
match && res.push(x);
}
);
return res;
}
});
}
// ---------------------------------------------------------------------------------------------------------------------------------------------------------
if (typeof (Array.prototype.coalesce) == 'undefined')
{
Array.coalescePredicate = function(x) { return (x === 0) || !!x; };
Object.defineProperty(Array.prototype, 'coalesce', {
value: function()
{
return this.where(Array.coalescePredicate);
}
});
}
if (typeof...