{"id":308517,"date":"2020-08-15T15:00:28","date_gmt":"2020-08-15T15:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308517"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308517","title":{"rendered":"LINQ \u043d\u0430 JavaScript \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514716\/\">\n<p>\u0428\u0435\u043b \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0434\u0435\u043d\u044c \u0441\u0430\u043c\u043e\u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438, \u0438 \u044f \u0434\u0435\u043b\u0430\u043b \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0437\u0430\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0434\u043d\u0435\u0439 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u043b\u0438. \u041d\u0443 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0430\u0441 \u0437\u043d\u0430\u043c\u0435\u043d\u0438\u0442\u044b\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0432\u044b\u0443\u0447\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u042f\u041f, \u043d\u043e\u0432\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438 \u0432\u0441\u0435 \u0442\u0430\u043a\u043e\u0435. \u0412 \u043e\u0431\u0449\u0435\u043c, \u044d\u0442\u043e \u0431\u044b\u043b \u0441\u0430\u043c\u044b\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0434\u0435\u043d\u044c, \u0441\u0430\u043c\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043f\u0430\u043d\u0434\u0435\u043c\u0438\u0438. \u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0435\u0449\u0430\u043b\u043e \u0431\u0435\u0434\u044b, \u043f\u043e\u043a\u0430 \u043e\u0434\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 \u043d\u0435 \u0432\u044b\u043f\u0430\u043b\u0430 \u0441\u043e stack overflow\u2026 \u0418 \u0432\u043e\u0442 \u0442\u0443\u0442-\u0442\u043e \u0432\u0441\u0435 \u0438 \u0437\u0430\u043f\u0443\u0437\u044b\u0440\u0438\u043b\u043e\u0441\u044c.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u044f \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0435, \u043d\u043e \u0442\u0430\u043a \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e.<\/p>\n<p>  <\/p>\n<h2 id=\"pochemu-linq\">\u041f\u043e\u0447\u0435\u043c\u0443 LINQ?<\/h2>\n<p>  <\/p>\n<p>\u0412\u043a\u0440\u0430\u0442\u0446\u0435 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u0432 \u043a\u0443\u0440\u0441\u0435:<\/p>\n<p>  <\/p>\n<blockquote><p>LINQ (Language-Integrated Query) \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u044f\u0437\u044b\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IEnumerable (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043c\u0430\u0441\u0441\u0438\u0432\u044b), \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 DataSet, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 XML.<\/p><\/blockquote>\n<p>\u0418 LINQ \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">string[] teams = { &quot;\u0411\u0430\u0432\u0430\u0440\u0438\u044f&quot;, &quot;\u0411\u043e\u0440\u0443\u0441\u0441\u0438\u044f&quot;, &quot;\u0420\u0435\u0430\u043b \u041c\u0430\u0434\u0440\u0438\u0434&quot;, &quot;\u041c\u0430\u043d\u0447\u0435\u0441\u0442\u0435\u0440 \u0421\u0438\u0442\u0438&quot;, &quot;\u041f\u0421\u0416&quot;, &quot;\u0411\u0430\u0440\u0441\u0435\u043b\u043e\u043d\u0430&quot; };  var selectedTeams = teams.Where(t=&gt;t.ToUpper().StartsWith(&quot;\u0411&quot;)).OrderBy(t =&gt; t);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0437 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c:<\/p>\n<p>  <\/p>\n<ul>\n<li>Lazy-computation<\/li>\n<li>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/li>\n<li>\u0423\u0434\u043e\u0431\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u0435 \u0437\u043d\u0430\u044e, \u043a\u0430\u043a \u0432\u044b, \u043d\u043e \u043b\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b\u043e \u0432\u0435\u0441\u043a\u0438\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0440\u0430\u0431\u043e\u0442\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"pristupaya-k-rabote\">\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u044f \u043a \u0440\u0430\u0431\u043e\u0442\u0435<\/h2>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u0440\u0430\u0437\u0443, \u0441 \u0448\u0430\u0448\u043a\u043e\u0439 \u043d\u0430\u0433\u043e\u043b\u043e, \u0431\u0440\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0435\u043b\u043e, \u043d\u043e \u043c\u044b \u0442\u0430\u043a \u043d\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043c \u2014 \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0435 \u043b\u044e\u0434\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0438\u0448\u0443\u0442 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0435 \u0432\u0435\u0449\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u043c\u0438\u043c\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u0445 LINQ:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e-\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u044b\u043c<\/li>\n<li>\u041a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u044b\u043c<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c <a href=\"https:\/\/benchmarkjs.com\" rel=\"nofollow\">Benchmark.js<\/a>. \u0410 \u0437\u0430 \u044d\u0442\u0430\u043b\u043e\u043d \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c <a href=\"https:\/\/lodash.com\/\" rel=\"nofollow\">Lodash<\/a>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u043c\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043c\u0430\u043b\u044c\u0447\u0438\u043a\u0430\u043c\u0438, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0435\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438, \u0442\u043e \u0432\u043e\u0442 <a href=\"https:\/\/github.com\/afferenslucem\/ursus-utilus-collections\" rel=\"nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a>, \u0430 \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0442\u043e \u0432\u043e\u0442 <a href=\"https:\/\/www.npmjs.com\/package\/ursus-utilus-collections\" rel=\"nofollow\">npm-\u043f\u0430\u043a\u0435\u0442<\/a>.<\/p>\n<p>  <\/p>\n<blockquote><p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u044f \u0431\u0443\u0434\u0443 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434, \u0442\u043e \u044d\u0442\u0443 \u043f\u043e\u0440\u0442\u044f\u043d\u043a\u0443 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c.<\/p><\/blockquote>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043c\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li>Where<\/li>\n<li>Sort<\/li>\n<li>Min<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u044f, \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e, \u0432\u0437\u044f\u043b \u043d\u0435 \u0441 \u043f\u043e\u0442\u043e\u043b\u043a\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>Where \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/li>\n<li>Sort \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u043e \u043d\u0435\u0433\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043e.<\/li>\n<li>Min \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"pristupim\">\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c<\/h2>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/c4\/pv\/xh\/c4pvxhmmev2fgeud4pa28txggmw.jpeg\"\/><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043c\u043e\u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/li>\n<li>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u043c \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/li>\n<\/ol>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nr\/49\/xo\/nr49xoijls7ljcztepqlfolfp0q.jpeg\"\/><\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%94%D0%B5%D0%BA%D0%BE%D1%80%D0%B0%D1%82%D0%BE%D1%80_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)\" rel=\"nofollow\">\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e, \u0442\u043e \u0441\u0445\u0435\u043c\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u043e\u0439:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/2p\/pu\/e7\/2ppue7afwbaolczwimxlqrm6hak.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u0442\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441, \u0443\u043c\u0435\u044e\u0449\u0438\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043c\u0435\u044e\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u043a\u0443\u0441\u043e\u0447\u043a\u0443 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">export class Collection&lt;T&gt; implements ICollection&lt;T&gt; {     protected inner: Collection&lt;T&gt;;     private _computed: T[] | null = null; \/\/ \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u0436\u0435 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f &quot;\u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c&quot;      public where(condition: FilterCondition&lt;T&gt;): ICollection&lt;T&gt; {         return new FilteringCollection&lt;T&gt;(this, condition);     }      public sort(condition?: CompareCondition&lt;T&gt; | undefined): ICollection&lt;T&gt; {         return new SortingCollection&lt;T&gt;(this, {             compare: condition         })     }      public min(predicate?: CompareCondition&lt;T&gt; | undefined): T {         return new MinAggregator(this, predicate).aggregate();     }      public toArray(): T[] {         return this.computed;     }      public [Symbol.iterator](): IterableIterator&lt;T&gt; {         return this.getIterator();     }      public getIterator(): IterableIterator&lt;T&gt; {         return this.computed[Symbol.iterator](); \/\/ \u041f\u043e \u0437\u0430\u0434\u0443\u043c\u043a\u0435, \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0438 \u0432 \u0446\u0438\u043a\u043b\u0435 for - of     }      private get computed(): T[] { \/\/ \u041b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f: \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u0430         if (this._computed == null) {             const result = this.materialize();              Object.freeze(result);              this._computed = result;         }         return this._computed     }      protected materialize(): T[] { \/\/ \u041c\u0435\u0442\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438         return this.inner.toArray();     } }<\/code><\/pre>\n<p>  <\/p>\n<p>&quot;\u0412 \u0447\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440?&quot; \u2014 \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b, \u0430 \u044f \u0432\u0430\u043c \u043e\u0442\u0432\u0435\u0447\u0443: <del>&quot;\u0423\u0447\u0438\u0442\u0435 \u043c\u0430\u0442\u0447\u0430\u0441\u0442\u044c&quot;<\/del>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0441\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">const collection = new Collection([6, 5, 4, 3, 2, 1]);  const result = collection.where(item =&gt; item % 2).sort(); \/\/ [1, 3, 5]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0435\u0433\u043e \u043f\u043e \u0448\u0430\u0433\u0430\u043c, \u043f\u0443\u0441\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">        const collection = new Collection([6, 5, 4, 3, 2, 1]); \/* 1) *\/const filtered = collection.where(item =&gt; item % 2); \/* 2) *\/const sorted = filtered.sort();<\/code><\/pre>\n<p>  <\/p>\n<p>1) \u041c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>where<\/code> \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Collection<\/code>, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0435 \u0432 \u043f\u043e\u043b\u0435 <code>inner<\/code>.<br \/>  2) \u041c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>sort<\/code> \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <code>FilteringCollection<\/code>, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0435 \u0432 \u043f\u043e\u043b\u0435 <code>inner<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0432\u0441\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0443\u0442 \u0432 \u0442\u0430\u043a\u043e\u043c \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0435:<\/p>\n<p>  <\/p>\n<p>1) \u0412\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f <code>materialize<\/code> \u0443 <code>FilteringCollection<\/code> \u0438 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 <code>[5, 3, 1]<\/code>.<br \/>  2) \u0412\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f <code>materialize<\/code> \u0443 <code>SortingCollection<\/code> \u0438 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 <code>[1, 3, 5]<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"where\">Where<\/h2>\n<p>  <\/p>\n<h3 id=\"realizaciya-filtruyuschego-dekoratora\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>  <\/p>\n<pre><code class=\"plaintext\">export class FilteringCollection&lt;T&gt; extends Collection&lt;T&gt; {     public constructor(iterable: Collection&lt;T&gt; | T[], private condition: FilterCondition&lt;T&gt;) {         super(iterable);     }      public where(condition: FilterCondition&lt;T&gt;): ICollection&lt;T&gt; { \/\/ \u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 where         const that = this;          const result = new FilteringCollection&lt;T&gt;(this.inner, item =&gt; condition(item) &amp;&amp; that.condition(item));          return result;     }      protected materialize(): T[] { \/\/ \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438         return this.inner.toArray().filter(this.condition);     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"poyasnenie\">\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438. \u0412\u0441\u0435.<br \/>  \u042d\u0442\u043e \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f where(). \u041a\u0440\u0430\u0441\u0438\u0432\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u043d\u0435\u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?<\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434 \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u0438\u0437 where:<\/p>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">_(cats).where(cat =&gt; cat.age &lt; 3).where(cat =&gt; cat.age &gt; 1).toArray()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">_(cats).where(cat =&gt; cat.age &lt; 3 &amp;&amp; (function(item){     return item.age &gt; 1; }(cat))).toArray()<\/code><\/pre>\n<p>  <\/p>\n<p>\u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u044d\u0442\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u043e\u0442 \u0442\u0443\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">public where(condition: FilterCondition&lt;T&gt;): ICollection&lt;T&gt; { \/\/ \u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 where         const result = new FilteringCollection&lt;T&gt;(this.inner, item =&gt; condition(item) &amp;&amp; this.condition(item)); \/\/ &lt;-- \u0442\u0443\u0442          return result;     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0434\u0430\u0435\u043c \u0432 \u043d\u043e\u0432\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 &quot;\u0441\u0440\u0430\u0449\u0435\u043d\u043d\u044b\u043c&quot;.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>materialize<\/code> \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>filter<\/code>. \u042f \u0432\u044b\u0431\u0440\u0430\u043b \u0435\u0433\u043e \u043a\u0430\u043a \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438. \u0412\u0441\u0435 \u0434\u0440\u0443\u0433\u043e\u0435, \u0447\u0442\u043e \u044f \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u043b\u043e \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">---------------------------------------------------- Filter for 1000000:  Where x 104 ops\/sec \u00b114.73% (61 runs sampled) Lodash filter x 609 ops\/sec \u00b10.67% (88 runs sampled) Native filter x 537 ops\/sec \u00b11.69% (85 runs sampled)  Double where x 102 ops\/sec \u00b111.51% (64 runs sampled) Double lodash filter x 368 ops\/sec \u00b11.00% (88 runs sampled) Double native filter x 336 ops\/sec \u00b11.08% (84 runs sampled)  10 where x 66.60 ops\/sec \u00b19.15% (59 runs sampled) 10 lodash filter x 99.44 ops\/sec \u00b11.20% (73 runs sampled) 10 native filter x 81.80 ops\/sec \u00b11.33% (70 runs sampled) ---------------------------------------------------- Filter for 1000:  Where x 24,296 ops\/sec \u00b10.90% (88 runs sampled) Lodash filter x 60,927 ops\/sec \u00b10.90% (89 runs sampled) Native filter x 204,522 ops\/sec \u00b16.76% (87 runs sampled)  Double where x 20,281 ops\/sec \u00b10.86% (90 runs sampled) Double lodash filter x 37,553 ops\/sec \u00b10.97% (90 runs sampled) Double native filter x 115,652 ops\/sec \u00b16.12% (91 runs sampled)  10 where x 9,559 ops\/sec \u00b11.09% (87 runs sampled) 10 lodash filter x 8,850 ops\/sec \u00b10.80% (87 runs sampled) 10 native filter x 22,507 ops\/sec \u00b19.22% (84 runs sampled) ---------------------------------------------------- Filter for 10:  Where x 1,788,009 ops\/sec \u00b10.81% (87 runs sampled) Lodash filter x 720,558 ops\/sec \u00b10.80% (84 runs sampled) Native filter x 14,917,151 ops\/sec \u00b10.61% (85 runs sampled)  Double where x 1,257,163 ops\/sec \u00b10.52% (95 runs sampled) Double lodash filter x 456,365 ops\/sec \u00b10.74% (76 runs sampled) Double native filter x 8,262,940 ops\/sec \u00b10.64% (90 runs sampled)  10 where x 489,733 ops\/sec \u00b10.67% (94 runs sampled) 10 lodash filter x 135,275 ops\/sec \u00b10.61% (94 runs sampled) 10 native filter x 1,350,316 ops\/sec \u00b10.94% (90 runs sampled) ----------------------------------------------------<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u0434\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445: \u041d\u0430\u0448\u0438 \u043f\u043e\u0431\u0435\u0436\u0434\u0430\u044e\u0442, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f\u0445.<br \/>  \u041a\u0441\u0442\u0430\u0442\u0438 \u0442\u0430\u043a\u043e\u0439 \u0440\u0430\u0441\u043a\u043b\u0430\u0434 \u0435\u0449\u0435 \u0438 \u0441 select (\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445).<\/p>\n<p>  <\/p>\n<h2 id=\"sort\">Sort<\/h2>\n<p>  <\/p>\n<h3 id=\"realizaciya-sortiruyuschego-dekoratora\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>  <\/p>\n<pre><code class=\"plaintext\">export class SortingCollection&lt;T, V = T&gt; extends Collection&lt;T&gt; implements ISortingCollection&lt;T&gt; {     private sortSettings: SortSettings&lt;T, V&gt;[];      public constructor(iterable: Collection&lt;T&gt;, ...sortSettings: SortSettings&lt;T, V&gt;[]) {         super(iterable);         this.sortSettings = _(sortSettings)         .where(item =&gt; !!item.compare || !!item.mapping) \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u043f\u043e\u043b\u0435\u0439 \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u043e \u043d\u0438\u043c         .toArray();     }      protected materialize(): T[] {         const comparer = new Comparer(this.sortSettings, this.defaultCompare);          return  Array.from(this.inner.toArray()).sort(this.sortSettings.length ? (first, second) =&gt; comparer.compare(first, second) : undefined);     }      private defaultCompare(first: V, second: V): number {         if(first &lt; second) {             return -1         } else if (second &lt; first) {             return 1         } else {             return 0;         }     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"poyasnenie-1\">\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438. \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0417\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>Comparer<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u043e\u0442 \u0444\u0430\u043a\u0442 \u0447\u0442\u043e Lodash, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 js \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sg\/d9\/sf\/sgd9sffwp4gfledrcvzttqmwx1q.jpeg\"\/><\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">---------------------------------------------------- Sort for 1000000:  Sort x 0.80 ops\/sec \u00b13.59% (6 runs sampled) Lodash sort x 0.97 ops\/sec \u00b127.98% (7 runs sampled) Native sort x 1.05 ops\/sec \u00b114.71% (7 runs sampled)  SortBy x 0.19 ops\/sec \u00b110.31% (5 runs sampled) Lodash SortBy x 0.37 ops\/sec \u00b17.21% (5 runs sampled) Sort after map x 0.47 ops\/sec \u00b18.67% (6 runs sampled) ---------------------------------------------------- Sort for 1000:  Sort x 1,121 ops\/sec \u00b10.77% (85 runs sampled) Lodash sort x 1,267 ops\/sec \u00b10.77% (89 runs sampled) Native sort x 1,274 ops\/sec \u00b10.88% (86 runs sampled)  SortBy x 488 ops\/sec \u00b11.45% (80 runs sampled) Lodash SortBy x 549 ops\/sec \u00b19.60% (70 runs sampled) Sort after map x 954 ops\/sec \u00b11.50% (83 runs sampled) ---------------------------------------------------- Sort for 10:  Sort x 171,700 ops\/sec \u00b11.38% (85 runs sampled) Lodash sort x 196,364 ops\/sec \u00b12.01% (80 runs sampled) Native sort x 250,820 ops\/sec \u00b10.96% (85 runs sampled)  SortBy x 114,064 ops\/sec \u00b10.90% (86 runs sampled) Lodash SortBy x 86,370 ops\/sec \u00b117.93% (67 runs sampled) Sort after map x 221,034 ops\/sec \u00b11.31% (87 runs sampled) ----------------------------------------------------<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0442\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445:<br \/>  \u00b1 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e.<\/p>\n<p>  <\/p>\n<h3 id=\"min\">Min<\/h3>\n<p>  <\/p>\n<h3 id=\"realizaciya-agreratora-poiska-minimalnogo-elementa\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0433\u0440\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/h3>\n<p>  <\/p>\n<pre><code class=\"plaintext\">export class MinAggregator&lt;T&gt; extends ReduceAggregator&lt;T&gt; {     public constructor(collection: ICollection&lt;T&gt;, condition?: CompareCondition&lt;T&gt;) {         super(collection, condition ? (first, second) =&gt; this.compare(first, second, condition) : (a, b) =&gt; a &lt; b ? a : b)     }      private compare(first: T, second: T, func: CompareCondition&lt;T&gt;): T {         return func(first, second) &lt; 0 ? first : second;     } }  export class ReduceAggregator&lt;T&gt; extends Aggregator&lt;T&gt; {     public constructor(private collection: ICollection&lt;T&gt;, protected predicate: ReduceCondition&lt;T&gt;){         super();     }      public aggregate(): T {         return this.collection.toArray().reduce((first, second) =&gt; this.predicate(first, second))     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0435 \u043e\u0436\u0438\u0434\u0430\u043b\u0438? \u0410 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<h3 id=\"poyasnenie-2\">\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u041d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d \u0447\u0442\u043e \u043e\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0443\u0436\u043d\u043e, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u0435\u0440\u0442\u043a\u0443.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">---------------------------------------------------- Aggregate for 1000000: Min x 43.69 ops\/sec \u00b128.48% (65 runs sampled) Lodash Min x 117 ops\/sec \u00b10.58% (73 runs sampled) ---------------------------------------------------- Aggregate for 1000: Min x 61,220 ops\/sec \u00b15.10% (87 runs sampled) Lodash Min x 111,452 ops\/sec \u00b10.72% (90 runs sampled) ---------------------------------------------------- Aggregate for 10: Min x 3,502,264 ops\/sec \u00b11.36% (86 runs sampled) Lodash Min x 4,181,189 ops\/sec \u00b11.48% (86 runs sampled) ---------------------------------------------------- Aggregate By for 1000000 disp 50: Min By x 23.81 ops\/sec \u00b12.02% (42 runs sampled) Lodash Min By x 42.66 ops\/sec \u00b12.46% (55 runs sampled) ---------------------------------------------------- Aggregate By for 1000 disp 50: Min By x 43,064 ops\/sec \u00b10.71% (86 runs sampled) Lodash Min By x 60,212 ops\/sec \u00b10.89% (87 runs sampled) ---------------------------------------------------- Aggregate By for 100 disp 50: Min By x 351,098 ops\/sec \u00b11.03% (81 runs sampled) Lodash Min By x 382,302 ops\/sec \u00b11.39% (76 runs sampled) ----------------------------------------------------<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>Lodash \u043f\u043e\u0431\u0435\u0434\u0438\u043b.<\/p>\n<p>  <\/p>\n<h2 id=\"itogi\">\u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>  <\/p>\n<p>\u042f \u0432\u0435\u0441\u0435\u043b\u043e \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u043b \u0432\u0440\u0435\u043c\u044f.<br \/>  \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u043f\u043b\u043e\u0445\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<blockquote><p>\u0415\u0441\u043b\u0438 \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u043e\u043d\u0438\u0437\u0438\u0442\u044c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u043e\u0442 \u0442\u0443\u0442:  <\/p>\n<pre><code class=\"plaintext\">this.inner.toArray().filter(this.condition);<\/code><\/pre>\n<p>  \u0442\u043e \u0431\u0443\u0434\u0443 \u0440\u0430\u0437 \u0443\u0437\u043d\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442!<\/p><\/blockquote>\n<p>\u041e\u0442\u043a\u0440\u044b\u0442 \u043a \u043a\u0440\u0438\u0442\u0438\u043a\u0435, \u0445\u043e\u0447\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u2192 <a href=\"https:\/\/github.com\/afferenslucem\/ursus-utilus-collections\" rel=\"nofollow\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a><br \/>  \u2192 <a href=\"https:\/\/www.npmjs.com\/package\/ursus-utilus-collections\" rel=\"nofollow\">Npm-\u043f\u0430\u043a\u0435\u0442<\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/514716\/\"> https:\/\/habr.com\/ru\/post\/514716\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514716\/\">\n<p>\u0428\u0435\u043b \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0434\u0435\u043d\u044c \u0441\u0430\u043c\u043e\u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438, \u0438 \u044f \u0434\u0435\u043b\u0430\u043b \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0437\u0430\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0434\u043d\u0435\u0439 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u043b\u0438. \u041d\u0443 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0430\u0441 \u0437\u043d\u0430\u043c\u0435\u043d\u0438\u0442\u044b\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0432\u044b\u0443\u0447\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u042f\u041f, \u043d\u043e\u0432\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438 \u0432\u0441\u0435 \u0442\u0430\u043a\u043e\u0435. \u0412 \u043e\u0431\u0449\u0435\u043c, \u044d\u0442\u043e \u0431\u044b\u043b \u0441\u0430\u043c\u044b\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0434\u0435\u043d\u044c, \u0441\u0430\u043c\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043f\u0430\u043d\u0434\u0435\u043c\u0438\u0438. \u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0435\u0449\u0430\u043b\u043e \u0431\u0435\u0434\u044b, \u043f\u043e\u043a\u0430 \u043e\u0434\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 \u043d\u0435 \u0432\u044b\u043f\u0430\u043b\u0430 \u0441\u043e stack overflow\u2026 \u0418 \u0432\u043e\u0442 \u0442\u0443\u0442-\u0442\u043e \u0432\u0441\u0435 \u0438 \u0437\u0430\u043f\u0443\u0437\u044b\u0440\u0438\u043b\u043e\u0441\u044c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308517","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308517"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308517\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}