text: /* ! https://github.com/akopachov/mini-linq-js */
  /* !
  The MIT License (MIT)
  
  Copyright (c) 2016 Alexander Kopachov <alex.kopachov@gmail.com> (https://www.linkedin.com/in/akopachov)
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
   */
  !function(){var stringTrim=function(a){return"string"!=typeof a||null===a?a:String.prototype.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},expressionCache={},LINQ={utils:{parseExpression:function(a){if("function"==typeof a)return a;if(null==a||"string"!=typeof a||a.indexOf("=>")<0)throw new SyntaxError('Expression "'+a+'" is invalid');if("function"==typeof expressionCache[a])return expressionCache[a];var b,c=a.split("=>"),d=stringTrim(c[0]).replace(/[\(\)\s]/gi,""),e=stringTrim(c[1]);try{e.indexOf("return")<0&&(e="return ("+e+")"),b=new Function(d,e)}catch(f){b=new Function(d,e)}if("function"!=typeof b)throw new SyntaxError('Expression "'+a+'" is invalid');return expressionCache[a]=b,b},getType:function(a){var b=typeof a;if("object"!==b)return b;if(null===a)return"null";var c=a.constructor,d="function"==typeof c&&c.name;return"string"==typeof d&&d.length>0?d:"object"},getDefaultValue:function(type){if("string"!=typeof type)throw new TypeError("Type must be a string.");switch(type){case"boolean":return!1;case"function":return function(){};case"null":return null;case"number":return 0;case"object":return{};case"string":return"";case"symbol":return Symbol();case"undefined":return}try{var ctor="function"==typeof this[type]?this[type]:eval(type);return new ctor}catch(e){return{}}},isArray:function(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}},methods:{any:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length>0;if("function"==typeof Array.prototype.some)return this.some(a);for(var b=0,c=this.length;b<c;b++)if(a(this[b],b,this))return!0;return!1},all:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.every)return this.every(a);var b=function(){return!a.apply(this,arguments)};return!LINQ.methods.any.apply(this,[b])},where:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Predicate is required");if("function"==typeof Array.prototype.filter)return this.filter(a);for(var b=[],c=0,d=this.length;c<d;c++)a(this[c],c,this)&&b.push(this[c]);return b},select:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");if("function"==typeof Array.prototype.map)return this.map(a);for(var b=[],c=0,d=this.length;c<d;c++)b.push(a(this[c],c,this));return b},selectMany:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Selector is required");for(var b=[],c=0,d=this.length;c<d;c++){var e=a(this[c],c,this);LINQ.utils.isArray(e)&&b.push(e)}return Array.prototype.concat.apply([],b)},count:function(a){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)return this.length;if("function"==typeof Array.prototype.filter)return this.filter(a).length;for(var b=0,c=0,d=this.length;c<d;c++)a(this[c],c,this)&&b++;return b},orderBy:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a<b?-1:a>b?1:0}),this.slice(0).sort(function(c,d){var e=a(c),f=a(d);return b(e,f)})},orderByDescending:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a<b?-1:a>b?1:0});var c=function(){return b.apply(this,arguments)*-1};return LINQ.methods.orderBy.apply(this,[a,c])},groupBy:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Key selector is required");"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return{group:a,values:b}});for(var c={},d=0,e=this.length;d<e;d++){var f=a(this[d],d,this);c[f]||(c[f]=[]),c[f].push(this[d])}var g=[];for(var h in c)c.hasOwnProperty(h)&&g.push(b(h,c[h]));return g},distinct:function(a,b){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d={},e=0,f=this.length;e<f;e++){var g=a(this[e],e,this);if(d[g]){for(var h=!0,i=0,j=d[g].length;i<j;i++)if(b(d[g][i],g)){h=!1;break}h&&(c.push(this[e]),d[g].push(g))}else d[g]=[g],c.push(this[e])}return c},firstOrDefault:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0}),"function"==typeof Array.prototype.find)return this.find(a)||null;for(var b=0,c=this.length;b<c;b++)if(a(this[b],b,this))return this[b];return null},lastOrDefault:function(a){"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(){return!0});for(var b=this.length-1;b>=0;b--)if(a(this[b],b,this))return this[b];return null},joinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;g<h;g++)for(var i=c(this[g],g,this),j=0,k=a.length;j<k;j++){var l=b(a[j],j,a);e(l,i)&&f.push(d(a[j],this[g]))}return f},groupJoinWith:function(a,b,c,d,e){if("string"==typeof b)b=LINQ.utils.parseExpression(b);else if("function"!=typeof b)throw new Error("Inner key selector is required");if("string"==typeof c)c=LINQ.utils.parseExpression(c);else if("function"!=typeof c)throw new Error("Outer key selector is required");if("string"==typeof d)d=LINQ.utils.parseExpression(d);else if("function"!=typeof d)throw new Error("Results selector is required");"string"==typeof e?e=LINQ.utils.parseExpression(e):"function"!=typeof e&&(e=function(a,b){return a===b});for(var f=[],g=0,h=this.length;g<h;g++){var i=c(this[g],g,this),j=LINQ.methods.where.apply(a,[function(c,d){return innerKey=b(a[d],d,a),e(innerKey,i)}]);f.push(d(j,this[g]))}return f},contains:function(a,b){var c;if("string"==typeof b){var d=LINQ.utils.parseExpression(b);c=function(b){return d(b,a)}}else c="function"!=typeof b?function(b){return b===a}:function(c){return b(c,a)};return LINQ.methods.any.apply(this,[c])},aggregate:function(a,b){if("string"==typeof a)a=LINQ.utils.parseExpression(a);else if("function"!=typeof a)throw new Error("Aggregator function is required");if(this.length<=0)return b;var c="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(this[0])):b;if("function"==typeof Array.prototype.reduce)return this.reduce(a,c);for(var d=0,e=this.length;d<e;d++)c=a(c,this[d],d,this);return c},sum:function(a,b){return"string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),b="undefined"==typeof b?LINQ.utils.getDefaultValue(LINQ.utils.getType(a(this[0],0,this))):b,LINQ.methods.aggregate.apply(this,[function(b,c,d,e){return b+a(c,d,e)},b])},min:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),!(this.length<=0))return LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b>f?f:b},a(this[0],0,this)])},max:function(a){if("string"==typeof a?a=LINQ.utils.parseExpression(a):"function"!=typeof a&&(a=function(a){return a}),!(this.length<=0))return LINQ.methods.aggregate.apply(this,[function(b,c,d,e){var f=a(c,d,e);return b<f?f:b},a(this[0],0,this)])},skip:function(a){if("number"!=typeof a||a<0)throw new TypeError("Count is required and should be a positive number");return this.slice(a,this.length)},take:function(a){if("number"!=typeof a||a<0)throw new TypeError("Count is required and should be a positive number");return this.slice(0,a)},ofType:function(a){if("string"!=typeof a)throw new TypeError("Type is required.");return LINQ.methods.where.apply(this,[function(b){return typeof b===a}])},union:function(a,b){return[].concat(this,a).distinct(function(a){return a},b)},except:function(a,b){"string"==typeof b?b=LINQ.utils.parseExpression(b):"function"!=typeof b&&(b=function(a,b){return a===b});for(var c=[],d=0,e=this.length;d<e;d++){for(var f=!0,g=0,h=a.length;g<h;g++)if(b(this[d],a[g])){f=!1;break}f&&c.push(this[d])}return c}}};LINQ.methods.firstOrDefault.finalize=!0,LINQ.methods.lastOrDefault.finalize=!0,LINQ.methods.count.finalize=!0,LINQ.methods.any.finalize=!0,LINQ.methods.contains.finalize=!0,LINQ.methods.all.finalize=!0,LINQ.methods.aggregate.finalize=!0,LINQ.methods.sum.finalize=!0,LINQ.methods.min.finalize=!0,LINQ.methods.max.finalize=!0;for(var key in LINQ.methods)LINQ.methods.hasOwnProperty(key)&&(Array.prototype[key]=LINQ.methods[key]);!function(a){var b=[function(b,c){if(b.name===c.name&&"where"===c.name){var d=a.utils.parseExpression(b.args[0]),e=a.utils.parseExpression(c.args[0]);return function(c,d){return{name:b.name,args:[function(){return c.apply(this,arguments)&&d.apply(this,arguments)}],fn:a.methods[b.name]}}(d,e)}return!1},function(b,c){if(b.name===c.name&&"select"===c.name){var d=a.utils.parseExpression(b.args[0]),e=a.utils.parseExpression(c.args[0]);return function(c,d){return{name:b.name,args:[function(){return d.apply(this,[c.apply(this,arguments)])}],fn:a.methods[b.name]}}(d,e)}return!1},function(a,b){var c=["orderBy","orderByDescending"];return!(!c.contains(a.name)||!c.contains(b.name))&&b},function(a,b){return"skip"==a.name&&"take"==b.name&&function(a,b){return{name:"skiptake",args:[a,b],fn:function(a,b){return this.slice(a,a+b)}}}(a.args[0],b.args[0])}],c=function(c){var d=this,e=c;d._modificatorQueue=[];var f=function(){for(var a=d._modificatorQueue.length,b=0;b<a;b++){var c=d._modificatorQueue[b];e=c.fn.apply(e,c.args)}return d._modificatorQueue.splice(0,a),a},g=function(){for(var a=0;a<d._modificatorQueue.length-1;){for(var c=d._modificatorQueue[a],e=d._modificatorQueue[a+1],f=!1,g=0,h=b.length;g<h;g++){var i=b[g],j=i(c,e);j&&(f=!0,d._modificatorQueue.splice(a+1,1),d._modificatorQueue[a]=j)}f||a++}};d.optimize=function(){return g(),d},d.toArray=function(){return e.length>100&&d._modificatorQueue.length>2&&d.optimize(),f(),a.utils.isArray(e)?e.slice(0):e}};Array.prototype.toLazy=function(){return new c(this)};for(var d in a.methods)a.methods.hasOwnProperty(d)&&(c.prototype[d]=function(b){return function(){var c=a.methods[b];return this._modificatorQueue.push({fn:a.methods[b],args:arguments,name:b}),c.finalize?this.toArray():this}}(d))}(LINQ),function(a){if("undefined"!=typeof ko&&ko.observableArray&&ko.observableArray.fn){Array.prototype.toObservableArray=function(){return ko.observableArray(this)},ko.observableArray.fn.toArray=function(){return this()};for(var b in a.methods)a.methods.hasOwnProperty(b)&&(ko.observableArray.fn[b]=function(b){return function(){return a.methods[b].apply(this(),arguments)}}(b))}}(LINQ)}();