You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1 lines
25 KiB

Enumerable=function(){var n=function(n){this.GetEnumerator=n},s,u;n.Choice=function(){var t=arguments[0]instanceof Array?arguments[0]:arguments;return new n(function(){return new i(r.Blank,function(){return this.Yield(t[Math.floor(Math.random()*t.length)])},r.Blank)})};n.Cycle=function(){var t=arguments[0]instanceof Array?arguments[0]:arguments;return new n(function(){var n=0;return new i(r.Blank,function(){return n>=t.length&&(n=0),this.Yield(t[n++])},r.Blank)})};n.Empty=function(){return new n(function(){return new i(r.Blank,function(){return!1},r.Blank)})};n.From=function(e){if(e==null)return n.Empty();if(e instanceof n)return e;if(typeof e==f.Number||typeof e==f.Boolean)return n.Repeat(e,1);if(typeof e==f.String)return new n(function(){var n=0;return new i(r.Blank,function(){return n<e.length?this.Yield(e.charAt(n++)):!1},r.Blank)});if(typeof e!=f.Function){if(typeof e.length==f.Number)return new u(e);if(!(e instanceof Object)&&t.IsIEnumerable(e))return new n(function(){var t=!0,n;return new i(function(){n=new Enumerator(e)},function(){return t?t=!1:n.moveNext(),n.atEnd()?!1:this.Yield(n.item())},r.Blank)})}return new n(function(){var n=[],t=0;return new i(function(){for(var t in e)e[t]instanceof Function||n.push({Key:t,Value:e[t]})},function(){return t<n.length?this.Yield(n[t++]):!1},r.Blank)})};n.Return=function(t){return n.Repeat(t,1)};n.Matches=function(t,u,f){return f==null&&(f=""),u instanceof RegExp&&(f+=u.ignoreCase?"i":"",f+=u.multiline?"m":"",u=u.source),f.indexOf("g")===-1&&(f+="g"),new n(function(){var n;return new i(function(){n=new RegExp(u,f)},function(){var i=n.exec(t);return i?this.Yield(i):!1},r.Blank)})};n.Range=function(t,i,r){return r==null&&(r=1),n.ToInfinity(t,r).Take(i)};n.RangeDown=function(t,i,r){return r==null&&(r=1),n.ToNegativeInfinity(t,r).Take(i)};n.RangeTo=function(t,i,r){return r==null&&(r=1),t<i?n.ToInfinity(t,r).TakeWhile(function(n){return n<=i}):n.ToNegativeInfinity(t,r).TakeWhile(function(n){return n>=i})};n.Repeat=function(t,u){return u!=null?n.Repeat(t).Take(u):new n(function(){return new i(r.Blank,function(){return this.Yield(t)},r.Blank)})};n.RepeatWithFinalize=function(r,u){return r=t.CreateLambda(r),u=t.CreateLambda(u),new n(function(){var n;return new i(function(){n=r()},function(){return this.Yield(n)},function(){n!=null&&(u(n),n=null)})})};n.Generate=function(u,f){return f!=null?n.Generate(u).Take(f):(u=t.CreateLambda(u),new n(function(){return new i(r.Blank,function(){return this.Yield(u())},r.Blank)}))};n.ToInfinity=function(t,u){return t==null&&(t=0),u==null&&(u=1),new n(function(){var n;return new i(function(){n=t-u},function(){return this.Yield(n+=u)},r.Blank)})};n.ToNegativeInfinity=function(t,u){return t==null&&(t=0),u==null&&(u=1),new n(function(){var n;return new i(function(){n=t+u},function(){return this.Yield(n-=u)},r.Blank)})};n.Unfold=function(u,f){return f=t.CreateLambda(f),new n(function(){var t=!0,n;return new i(r.Blank,function(){return t?(t=!1,n=u,this.Yield(n)):(n=f(n),this.Yield(n))},r.Blank)})};n.prototype={CascadeBreadthFirst:function(r,u){var f=this;return r=t.CreateLambda(r),u=t.CreateLambda(u),new n(function(){var e,s=0,o=[];return new i(function(){e=f.GetEnumerator()},function(){for(;;){if(e.MoveNext())return o.push(e.Current()),this.Yield(u(e.Current(),s));var i=n.From(o).SelectMany(function(n){return r(n)});if(i.Any())s++,o=[],t.Dispose(e),e=i.GetEnumerator();else return!1}},function(){t.Dispose(e)})})},CascadeDepthFirst:function(r,u){var f=this;return r=t.CreateLambda(r),u=t.CreateLambda(u),new n(function(){var o=[],e;return new i(function(){e=f.GetEnumerator()},function(){for(;;){if(e.MoveNext()){var i=u(e.Current(),o.length);return o.push(e),e=n.From(r(e.Current())).GetEnumerator(),this.Yield(i)}if(o.length<=0)return!1;t.Dispose(e);e=o.pop()}},function(){try{t.Dispose(e)}finally{n.From(o).ForEach(function(n){n.Dispose()})}})})},Flatten:function(){var u=this;return new n(function(){var e,f=null;return new i(function(){e=u.GetEnumerator()},function(){for(;;){if(f!=null){if(f.MoveNext())return this.Yield(f.Current());f=null}if(e.MoveNext())if(e.Current()instanceof Array){t.Dispose(f);f=n.From(e.Current()).SelectMany(r.Identity).Flatten().GetEnumerator();continue}else return this.Yield(e.Current());return!1}},function(){try{t.Dispose(e)}finally{t.Dispose(f)}})})},Pairwise:function(r){var u=this;return r=t.CreateLambda(r),new n(function(){var n;return new i(function(){n=u.GetEnumerator();n.MoveNext()},function(){var t=n.Current();return n.MoveNext()?this.Yield(r(t,n.Current())):!1},function(){t.Dispose(n)})})},Scan:function(r,u,f){var e,o;return f!=null?this.Scan(r,u).Select(f):(u==null?(u=t.CreateLambda(r),e=!1):(u=t.CreateLambda(u),e=!0),o=this,new n(function(){var n,f,s=!0;return new i(function(){n=o.GetEnumerator()},function(){if(s){if(s=!1,e)return this.Yield(f=r);if(n.MoveNext())return this.Yield(f=n.Current())}return n.MoveNext()?this.Yield(f=u(f,n.Current())):!1},function(){t.Dispose(n)})}))},Select:function(r){var u=this;return r=t.CreateLambda(r),new n(function(){var n,f=0;return new i(function(){n=u.GetEnumerator()},function(){return n.MoveNext()?this.Yield(r(n.Current(),f++)):!1},function(){t.Dispose(n)})})},SelectMany:function(r,u){var f=this;return r=t.CreateLambda(r),u==null&&(u=function(n,t){return t}),u=t.CreateLambda(u),new n(function(){var o,e=undefined,s=0;return new i(function(){o=f.GetEnumerator()},function(){if(e===undefined&&!o.MoveNext())return!1;do{if(e==null){var i=r(o.Current(),s++);e=n.From(i).GetEnumerator()}if(e.MoveNext())return this.Yield(u(o.Current(),e.Current()));t.Dispose(e);e=null}while(o.MoveNext());return!1},function(){try{t.Dispose(o)}finally{t.Dispose(e)}})})},Where:function(r){r=t.CreateLambda(r);var u=this;return new n(function(){var n,f=0;return new i(function(){n=u.GetEnumerator()},function(){while(n.MoveNext())if(r(n.Current(),f++))return this.Yield(n.Current());return!1},function(){t.Dispose(n)})})},OfType:function(n){var t;switch(n){case Number:t=f.Number;break;case String:t=f.String;break;case Boolean:t=f.Boolean;break;case Function:t=f.Function;break;default:t=null}return t===null?this.Where(function(t){return t instanceof n}):this.Where(function(n){return typeof n===t})},Zip:function(r,u){u=t.CreateLambda(u);var f=this;return new n(function(){var e,o,s=0;return new i(function(){e=f.GetEnumerator();o=n.From(r).GetEnumerator()},function(){return e.MoveNext()&&o.MoveNext()?this.Yield(u(e.Current(),o.Current(),s++)):!1},function(){try{t.Dispose(e)}finally{t.Dispose(o)}})})},Join:function(u,f,e,o,s){f=t.CreateLambda(f);e=t.CreateLambda(e);o=t.CreateLambda(o);s=t.CreateLambda(s);var h=this;return new n(function(){var c,a,l=null,v=0;return new i(function(){c=h.GetEnumerator();a=n.From(u).ToLookup(e,r.Identity,s)},function(){for(var n,t;;){if(l!=null){if(n=l[v++],n!==undefined)return this.Yield(o(c.Current(),n));n=null;v=0}if(c.MoveNext())t=f(c.Current()),l=a.Get(t).ToArray();else return!1}},function(){t.Dispose(c)})})},GroupJoin:function(u,f,e,o,s){f=t.CreateLambda(f);e=t.CreateLambda(e);o=t.CreateLambda(o);s=t.CreateLambda(s);var h=this;return new n(function(){var c=h.GetEnumerator(),l=null;return new i(function(){c=h.GetEnumerator();l=n.From(u).ToLookup(e,r.Identity,s)},function(){if(c.MoveNext()){var n=l.Get(f(c.Current()));return this.Yield(o(c.Current(),n))}return!1},function(){t.Dispose(c)})})},All:function(n){n=t.CreateLambda(n);var i=!0;return this.ForEach(function(t){if(!n(t))return i=!1,!1}),i},Any:function(n){n=t.CreateLambda(n);var i=this.GetEnumerator();try{if(arguments.length==0)return i.MoveNext();while(i.MoveNext())if(n(i.Current()))return!0;return!1}finally{t.Dispose(i)}},Concat:function(r){var u=this;return new n(function(){var e,f;return new i(function(){e=u.GetEnumerator()},function(){if(f==null){if(e.MoveNext())return this.Yield(e.Current());f=n.From(r).GetEnumerator()}return f.MoveNext()?this.Yield(f.Current()):!1},function(){try{t.Dispose(e)}finally{t.Dispose(f)}})})},Insert:function(r,u){var f=this;return new n(function(){var o,e,s=0,h=!1;return new i(function(){o=f.GetEnumerator();e=n.From(u).GetEnumerator()},function(){return s==r&&e.MoveNext()?(h=!0,this.Yield(e.Current())):o.MoveNext()?(s++,this.Yield(o.Current())):!h&&e.MoveNext()?this.Yield(e.Current()):!1},function(){try{t.Dispose(o)}finally{t.Dispose(e)}})})},Alternate:function(t){return t=n.Return(t),this.SelectMany(function(i){return n.Return(i).Concat(t)}).TakeExceptLast()},Contains:function(n,i){i=t.CreateLambda(i);var r=this.GetEnumerator();try{while(r.MoveNext())if(i(r.Current())===n)return!0;return!1}finally{t.Dispose(r)}},DefaultIfEmpty:function(r){var u=this;return new n(function(){var n,f=!0;return new i(function(){n=u.GetEnumerator()},function(){return n.MoveNext()?(f=!1,this.Yield(n.Current())):f?(f=!1,this.Yield(r)):!1},function(){t.Dispose(n)})})},Distinct:function(t){return this.Except(n.Empty(),t)},Except:function(r,u){u=t.CreateLambda(u);var f=this;return new n(function(){var e,o;return new i(function(){e=f.GetEnumerator();o=new h(u);n.From(r).ForEach(function(n){o.Add(n)})},function(){while(e.MoveNext()){var n=e.Current();if(!o.Contains(n))return o.Add(n),this.Yield(n)}return!1},function(){t.Dispose(e)})})},Intersect:function(r,u){u=t.CreateLambda(u);var f=this;return new n(function(){var e,o,s;return new i(function(){e=f.GetEnumerator();o=new h(u);n.From(r).ForEach(function(n){o.Add(n)});s=new h(u)},function(){while(e.MoveNext()){var n=e.Current();if(!s.Contains(n)&&o.Contains(n))return s.Add(n),this.Yield(n)}return!1},function(){t.Dispose(e)})})},SequenceEqual:function(i,r){var f,u;r=t.CreateLambda(r);f=this.GetEnumerator();try{u=n.From(i).GetEnumerator();try{while(f.MoveNext())if(!u.MoveNext()||r(f.Current())!==r(u.Current()))return!1;return u.MoveNext()?!1:!0}finally{t.Dispose(u)}}finally{t.Dispose(f)}},Union:function(r,u){u=t.CreateLambda(u);var f=this;return new n(function(){var s,e,o;return new i(function(){s=f.GetEnumerator();o=new h(u)},function(){var t;if(e===undefined){while(s.MoveNext())if(t=s.Current(),!o.Contains(t))return o.Add(t),this.Yield(t);e=n.From(r).GetEnumerator()}while(e.MoveNext())if(t=e.Current(),!o.Contains(t))return o.Add(t),this.Yield(t);return!1},function(){try{t.Dispose(s)}finally{t.Dispose(e)}})})},OrderBy:function(n){return new e(this,n,!1)},OrderByDescending:function(n){return new e(this,n,!0)},Reverse:function(){var t=this;return new n(function(){var n,u;return new i(function(){n=t.ToArray();u=n.length},function(){return u>0?this.Yield(n[--u]):!1},r.Blank)})},Shuffle:function(){var t=this;return new n(function(){var n;return new i(function(){n=t.ToArray()},function(){if(n.length>0){var t=Math.floor(Math.random()*n.length);return this.Yield(n.splice(t,1)[0])}return!1},r.Blank)})},GroupBy:function(r,u,f,e){var o=this;return r=t.CreateLambda(r),u=t.CreateLambda(u),f!=null&&(f=t.CreateLambda(f)),e=t.CreateLambda(e),new n(function(){var n;return new i(function(){n=o.ToLookup(r,u,e).ToEnumerable().GetEnumerator()},function(){while(n.MoveNext())return f==null?this.Yield(n.Current()):this.Yield(f(n.Current().Key(),n.Current()));return!1},function(){t.Dispose(n)})})},PartitionBy:function(r,u,f,e){var s=this,o;return r=t.CreateLambda(r),u=t.CreateLambda(u),e=t.CreateLambda(e),f==null?(o=!1,f=function(n,t){return new c(n,t)}):(o=!0,f=t.CreateLambda(f)),new n(function(){var h,l,a,c=[];return new i(function(){h=s.GetEnumerator();h.MoveNext()&&(l=r(h.Current()),a=e(l),c.push(u(h.Current())))},function(){for(var t,i;(t=h.MoveNext())==!0;)if(a===e(r(h.Current())))c.push(u(h.Current()));else break;return c.length>0?(i=o?f(l,n.From(c)):f(l,c),t?(l=r(h.Current()),a=e(l),c=[u(h.Current())]):c=[],this.Yield(i)):!1},function(){t.Dispose(h)})})},BufferWithCount:function(r){var u=this;return new n(function(){var n;return new i(function(){n=u.GetEnumerator()},function(){for(var t=[],i=0;n.MoveNext();)if(t.push(n.Current()),++i>=r)return this.Yield(t);return t.length>0?this.Yield(t):!1},function(){t.Dispose(n)})})},Aggregate:function(n,t,i){return this.Scan(n,t,i).Last()},Average:function(n){n=t.CreateLambda(n);var i=0,r=0;return this.ForEach(function(t){i+=n(t);++r}),i/r},Count:function(n){n=n==null?r.True:t.CreateLambda(n);var i=0;return this.ForEach(function(t,r){n(t,r)&&++i}),i},Max:function(n){return n==null&&(n=r.Identity),this.Select(n).Aggregate(function(n,t){return n>t?n:t})},Min:function(n){return n==null&&(n=r.Identity),this.Select(n).Aggregate(function(n,t){return n<t?n:t})},MaxBy:function(n){return n=t.CreateLambda(n),this.Aggregate(function(t,i){return n(t)>n(i)?t:i})},MinBy:function(n){return n=t.CreateLambda(n),this.Aggregate(function(t,i){return n(t)<n(i)?t:i})},Sum:function(n){return n==null&&(n=r.Identity),this.Select(n).Aggregate(0,function(n,t){return n+t})},ElementAt:function(n){var t,i=!1;if(this.ForEach(function(r,u){if(u==n)return t=r,i=!0,!1}),!i)throw new Error("index is less than 0 or greater than or equal to the number of elements in source.");return t},ElementAtOrDefault:function(n,t){var i,r=!1;return this.ForEach(function(t,u){if(u==n)return i=t,r=!0,!1}),r?i:t},First:function(n){if(n!=null)return this.Where(n).First();var t,i=!1;if(this.ForEach(function(n){return t=n,i=!0,!1}),!i)throw new Error("First:No element satisfies the condition.");return t},FirstOrDefault:function(n,t){if(t!=null)return this.Where(t).FirstOrDefault(n);var i,r=!1;return this.ForEach(function(n){return i=n,r=!0,!1}),r?i:n},Last:function(n){if(n!=null)return this.Where(n).Last();var t,i=!1;if(this.ForEach(function(n){i=!0;t=n}),!i)throw new Error("Last:No element satisfies the condition.");return t},LastOrDefault:function(n,t){if(t!=null)return this.Where(t).LastOrDefault(n);var i,r=!1;return this.ForEach(function(n){r=!0;i=n}),r?i:n},Single:function(n){if(n!=null)return this.Where(n).Single();var i,t=!1;if(this.ForEach(function(n){if(t)throw new Error("Single:sequence contains more than one element.");else t=!0,i=n}),!t)throw new Error("Single:No element satisfies the condition.");return i},SingleOrDefault:function(n,t){if(t!=null)return this.Where(t).SingleOrDefault(n);var r,i=!1;return this.ForEach(function(n){if(i)throw new Error("Single:sequence contains more than one element.");else i=!0,r=n}),i?r:n},Skip:function(r){var u=this;return new n(function(){var n,f=0;return new i(function(){for(n=u.GetEnumerator();f++<r&&n.MoveNext(););},function(){return n.MoveNext()?this.Yield(n.Current()):!1},function(){t.Dispose(n)})})},SkipWhile:function(r){r=t.CreateLambda(r);var u=this;return new n(function(){var n,e=0,f=!1;return new i(function(){n=u.GetEnumerator()},function(){while(!f)if(n.MoveNext()){if(!r(n.Current(),e++))return f=!0,this.Yield(n.Current());continue}else return!1;return n.MoveNext()?this.Yield(n.Current()):!1},function(){t.Dispose(n)})})},Take:function(r){var u=this;return new n(function(){var n,f=0;return new i(function(){n=u.GetEnumerator()},function(){return f++<r&&n.MoveNext()?this.Yield(n.Current()):!1},function(){t.Dispose(n)})})},TakeWhile:function(r){r=t.CreateLambda(r);var u=this;return new n(function(){var n,f=0;return new i(function(){n=u.GetEnumerator()},function(){return n.MoveNext()&&r(n.Current(),f++)?this.Yield(n.Current()):!1},function(){t.Dispose(n)})})},TakeExceptLast:function(r){r==null&&(r=1);var u=this;return new n(function(){if(r<=0)return u.GetEnumerator();var n,f=[];return new i(function(){n=u.GetEnumerator()},function(){while(n.MoveNext()){if(f.length==r)return f.push(n.Current()),this.Yield(f.shift());f.push(n.Current())}return!1},function(){t.Dispose(n)})})},TakeFromLast:function(r){if(r<=0||r==null)return n.Empty();var u=this;return new n(function(){var o,f,e=[];return new i(function(){o=u.GetEnumerator()},function(){while(o.MoveNext())e.length==r&&e.shift(),e.push(o.Current());return f==null&&(f=n.From(e).GetEnumerator()),f.MoveNext()?this.Yield(f.Current()):!1},function(){t.Dispose(f)})})},IndexOf:function(n){var t=null;return this.ForEach(function(i,r){if(i===n)return t=r,!0}),t!==null?t:-1},LastIndexOf:function(n){var t=-1;return this.ForEach(function(i,r){i===n&&(t=r)}),t},ToArray:function(){var n=[];return this.ForEach(function(t){n.push(t)}),n},ToLookup:function(n,i,r){n=t.CreateLambda(n);i=t.CreateLambda(i);r=t.CreateLambda(r);var u=new h(r);return this.ForEach(function(t){var r=n(t),f=i(t),e=u.Get(r);e!==undefined?e.push(f):u.Add(r,[f])}),new a(u)},ToObject:function(n,i){n=t.CreateLambda(n);i=t.CreateLambda(i);var r={};return this.ForEach(function(t){r[n(t)]=i(t)}),r},ToDictionary:function(n,i,r){n=t.CreateLambda(n);i=t.CreateLambda(i);r=t.CreateLambda(r);var u=new h(r);return this.ForEach(function(t){u.Add(n(t),i(t))}),u},ToJSON:function(n,t){return JSON.stringify(this.ToArray(),n,t)},ToString:function(n,t){return n==null&&(n=""),t==null&&(t=r.Identity),this.Select(t).ToArray().join(n)},Do:function(r){var u=this;return r=t.CreateLambda(r),new n(function(){var n,f=0;return new i(function(){n=u.GetEnumerator()},function(){return n.MoveNext()?(r(n.Current(),f++),this.Yield(n.Current())):!1},function(){t.Dispose(n)})})},ForEach:function(n){n=t.CreateLambda(n);var r=0,i=this.GetEnumerator();try{while(i.MoveNext())if(n(i.Current(),r++)===!1)break}finally{t.Dispose(i)}},Write:function(n,i){n==null&&(n="");i=t.CreateLambda(i);var r=!0;this.ForEach(function(t){r?r=!1:document.write(n);document.write(i(t))})},WriteLine:function(n){n=t.CreateLambda(n);this.ForEach(function(t){document.write(n(t));document.write("<br />")})},Force:function(){var n=this.GetEnumerator();try{while(n.MoveNext());}finally{t.Dispose(n)}},Let:function(r){r=t.CreateLambda(r);var u=this;return new n(function(){var f;return new i(function(){f=n.From(r(u)).GetEnumerator()},function(){return f.MoveNext()?this.Yield(f.Current()):!1},function(){t.Dispose(f)})})},Share:function(){var u=this,t;return new n(function(){return new i(function(){t==null&&(t=u.GetEnumerator())},function(){return t.MoveNext()?this.Yield(t.Current()):!1},r.Blank)})},MemoizeAll:function(){var f=this,t,u;return new n(function(){var n=-1;return new i(function(){u==null&&(u=f.GetEnumerator(),t=[])},function(){return(n++,t.length<=n)?u.MoveNext()?this.Yield(t[n]=u.Current()):!1:this.Yield(t[n])},r.Blank)})},Catch:function(r){r=t.CreateLambda(r);var u=this;return new n(function(){var n;return new i(function(){n=u.GetEnumerator()},function(){try{return n.MoveNext()?this.Yield(n.Current()):!1}catch(t){return r(t),!1}},function(){t.Dispose(n)})})},Finally:function(r){r=t.CreateLambda(r);var u=this;return new n(function(){var n;return new i(function(){n=u.GetEnumerator()},function(){return n.MoveNext()?this.Yield(n.Current()):!1},function(){try{t.Dispose(n)}finally{r()}})})},Trace:function(n,i){return n==null&&(n="Trace"),i=t.CreateLambda(i),this.Do(function(t){console.log(n,":",i(t))})}};var r={Identity:function(n){return n},True:function(){return!0},Blank:function(){}},f={Boolean:"boolean",Number:"number",String:"string",Object:"object",Undefined:typeof undefined,Function:typeof function(){}},t={CreateLambda:function(n){if(n==null)return r.Identity;if(typeof n==f.String){if(n=="")return r.Identity;if(n.indexOf("=>")==-1)return new Function("$,$$,$$$,$$$$","return "+n);var t=n.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/);return new Function(t[1],"return "+t[2])}return n},IsIEnumerable:function(n){if(typeof Enumerator!=f.Undefined)try{return new Enumerator(n),!0}catch(t){}return!1},Compare:function(n,t){return n===t?0:n>t?1:-1},Dispose:function(n){n!=null&&n.Dispose()}},o={Before:0,Running:1,After:2},i=function(n,t,i){var u=new l,r=o.Before;this.Current=u.Current;this.MoveNext=function(){try{switch(r){case o.Before:r=o.Running;n();case o.Running:return t.apply(u)?!0:(this.Dispose(),!1);case o.After:return!1}}catch(i){this.Dispose();throw i;}};this.Dispose=function(){if(r==o.Running)try{i()}finally{r=o.After}}},l=function(){var n=null;this.Current=function(){return n};this.Yield=function(t){return n=t,!0}},e=function(n,i,r,u){this.source=n;this.keySelector=t.CreateLambda(i);this.descending=r;this.parent=u};e.prototype=new n;e.prototype.CreateOrderedEnumerable=function(n,t){return new e(this.source,n,t,this)};e.prototype.ThenBy=function(n){return this.CreateOrderedEnumerable(n,!1)};e.prototype.ThenByDescending=function(n){return this.CreateOrderedEnumerable(n,!0)};e.prototype.GetEnumerator=function(){var u=this,t,n,f=0;return new i(function(){t=[];n=[];u.source.ForEach(function(i,r){t.push(i);n.push(r)});var i=s.Create(u,null);i.GenerateKeys(t);n.sort(function(n,t){return i.Compare(n,t)})},function(){return f<n.length?this.Yield(t[n[f++]]):!1},r.Blank)};s=function(n,t,i){this.keySelector=n;this.descending=t;this.child=i;this.keys=null};s.Create=function(n,t){var i=new s(n.keySelector,n.descending,t);return n.parent!=null?s.Create(n.parent,i):i};s.prototype.GenerateKeys=function(n){for(var i=n.length,u=this.keySelector,r=new Array(i),t=0;t<i;t++)r[t]=u(n[t]);this.keys=r;this.child!=null&&this.child.GenerateKeys(n)};s.prototype.Compare=function(n,i){var r=t.Compare(this.keys[n],this.keys[i]);if(r==0){if(this.child!=null)return this.child.Compare(n,i);r=t.Compare(n,i)}return this.descending?-r:r};u=function(n){this.source=n};u.prototype=new n;u.prototype.Any=function(t){return t==null?this.source.length>0:n.prototype.Any.apply(this,arguments)};u.prototype.Count=function(t){return t==null?this.source.length:n.prototype.Count.apply(this,arguments)};u.prototype.ElementAt=function(t){return 0<=t&&t<this.source.length?this.source[t]:n.prototype.ElementAt.apply(this,arguments)};u.prototype.ElementAtOrDefault=function(n,t){return 0<=n&&n<this.source.length?this.source[n]:t};u.prototype.First=function(t){return t==null&&this.source.length>0?this.source[0]:n.prototype.First.apply(this,arguments)};u.prototype.FirstOrDefault=function(t,i){return i!=null?n.prototype.FirstOrDefault.apply(this,arguments):this.source.length>0?this.source[0]:t};u.prototype.Last=function(t){return t==null&&this.source.length>0?this.source[this.source.length-1]:n.prototype.Last.apply(this,arguments)};u.prototype.LastOrDefault=function(t,i){return i!=null?n.prototype.LastOrDefault.apply(this,arguments):this.source.length>0?this.source[this.source.length-1]:t};u.prototype.Skip=function(t){var u=this.source;return new n(function(){var n;return new i(function(){n=t<0?0:t},function(){return n<u.length?this.Yield(u[n++]):!1},r.Blank)})};u.prototype.TakeExceptLast=function(n){return n==null&&(n=1),this.Take(this.source.length-n)};u.prototype.TakeFromLast=function(n){return this.Skip(this.source.length-n)};u.prototype.Reverse=function(){var t=this.source;return new n(function(){var n;return new i(function(){n=t.length},function(){return n>0?this.Yield(t[--n]):!1},r.Blank)})};u.prototype.SequenceEqual=function(t,i){return(t instanceof u||t instanceof Array)&&i==null&&n.From(t).Count()!=this.Count()?!1:n.prototype.SequenceEqual.apply(this,arguments)};u.prototype.ToString=function(t,i){return i!=null||!(this.source instanceof Array)?n.prototype.ToString.apply(this,arguments):(t==null&&(t=""),this.source.join(t))};u.prototype.GetEnumerator=function(){var n=this.source,t=0;return new i(r.Blank,function(){return t<n.length?this.Yield(n[t++]):!1},r.Blank)};var h=function(){var t=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},u=function(n){return n===null?"null":n===undefined?"undefined":typeof n.toString===f.Function?n.toString():Object.prototype.toString.call(n)},s=function(n,t){this.Key=n;this.Value=t;this.Prev=null;this.Next=null},e=function(){this.First=null;this.Last=null},o;return e.prototype={AddLast:function(n){this.Last!=null?(this.Last.Next=n,n.Prev=this.Last,this.Last=n):this.First=this.Last=n},Replace:function(n,t){n.Prev!=null?(n.Prev.Next=t,t.Prev=n.Prev):this.First=t;n.Next!=null?(n.Next.Prev=t,t.Next=n.Next):this.Last=t},Remove:function(n){n.Prev!=null?n.Prev.Next=n.Next:this.First=n.Next;n.Next!=null?n.Next.Prev=n.Prev:this.Last=n.Prev}},o=function(n){this.count=0;this.entryList=new e;this.buckets={};this.compareSelector=n==null?r.Identity:n},o.prototype={Add:function(n,i){var h=this.compareSelector(n),o=u(h),e=new s(n,i),r,f;if(t(this.buckets,o)){for(r=this.buckets[o],f=0;f<r.length;f++)if(this.compareSelector(r[f].Key)===h){this.entryList.Replace(r[f],e);r[f]=e;return}r.push(e)}else this.buckets[o]=[e];this.count++;this.entryList.AddLast(e)},Get:function(n){var e=this.compareSelector(n),o=u(e),r,i,f;if(!t(this.buckets,o))return undefined;for(r=this.buckets[o],i=0;i<r.length;i++)if(f=r[i],this.compareSelector(f.Key)===e)return f.Value;return undefined},Set:function(n,i){var o=this.compareSelector(n),h=u(o),f,r,e;if(t(this.buckets,h))for(f=this.buckets[h],r=0;r<f.length;r++)if(this.compareSelector(f[r].Key)===o)return e=new s(n,i),this.entryList.Replace(f[r],e),f[r]=e,!0;return!1},Contains:function(n){var f=this.compareSelector(n),e=u(f),r,i;if(!t(this.buckets,e))return!1;for(r=this.buckets[e],i=0;i<r.length;i++)if(this.compareSelector(r[i].Key)===f)return!0;return!1},Clear:function(){this.count=0;this.buckets={};this.entryList=new e},Remove:function(n){var e=this.compareSelector(n),f=u(e),i,r;if(t(this.buckets,f))for(i=this.buckets[f],r=0;r<i.length;r++)if(this.compareSelector(i[r].Key)===e){this.entryList.Remove(i[r]);i.splice(r,1);i.length==0&&delete this.buckets[f];this.count--;return}},Count:function(){return this.count},ToEnumerable:function(){var t=this;return new n(function(){var n;return new i(function(){n=t.entryList.First},function(){if(n!=null){var t={Key:n.Key,Value:n.Value};return n=n.Next,this.Yield(t)}return!1},r.Blank)})}},o}(),a=function(t){this.Count=function(){return t.Count()};this.Get=function(i){return n.From(t.Get(i))};this.Contains=function(n){return t.Contains(n)};this.ToEnumerable=function(){return t.ToEnumerable().Select(function(n){return new c(n.Key,n.Value)})}},c=function(n,t){this.Key=function(){return n};u.call(this,t)};return c.prototype=new u,n}();