{"id":314859,"date":"2020-12-14T21:00:52","date_gmt":"2020-12-14T21:00:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=314859"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=314859","title":{"rendered":"\u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e \u0432 \u0446\u0438\u043a\u043b"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u041c\u0430\u043a\u0441\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 Stack Overflow exception.<\/p>\n<p>  <\/p>\n<h2 id=\"zachem-maksim-eto-sdelal\">\u0417\u0430\u0447\u0435\u043c \u041c\u0430\u043a\u0441\u0438\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b?<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043b\u044e\u0431\u0438\u0442 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0438 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0435 \u043d\u0430 \u0435\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041e\u043d \u043d\u0435 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0438\u0448\u0435\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function factorial(n) {   let res = 1;   for (let i = 2; i &lt;= n; i++) {     res *= i;   }   return res; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043d \u0445\u043e\u0447\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const factorial = (n) =&gt; (n &gt; 1 ? n * factorial(n - 1) : 1);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u043d \u0432\u0438\u0434\u0438\u0442 \u044d\u0442\u043e:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mf\/6-\/hx\/mf6-hxx83m3v-llxd0opzgm2n0u.png\"><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"pochemu-elegantnyy-algoritm-ne-srabotal\">\u041f\u043e\u0447\u0435\u043c\u0443 \u00ab\u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0439\u00bb \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b?<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 Javascript \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>factorial<\/code> \u043a\u043b\u0430\u0434\u0451\u0442 \u0432 \u0441\u0442\u0435\u043a \u0437\u0430\u043f\u0438\u0441\u044c \u043e \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u0442\u0435\u043a\u0430 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u2014 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u044d\u0442\u0430 \u043e\u0448\u0438\u0431\u043a\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u043b\u0435\u0442\u0435\u043b\u0430 \u043f\u0440\u0438 10700+ \u0432\u043b\u043e\u0436\u0435\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"chto-delat-maksimu\">\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u041c\u0430\u043a\u0441\u0438\u043c\u0443?<\/h2>\n<p>  <\/p>\n<p>\u0417\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u043b\u0438 \u0441\u0442\u043e\u0439\u043a\u043e\u0441\u0442\u0438 \u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043d \u043e\u0448\u0438\u0431\u0441\u044f. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043b\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a \u0431\u0430\u0437\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438 \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u0443\u0441\u0442\u044c \u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0442\u0438\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043a \u043a\u043e\u0434\u0443 \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u041c\u0430\u043a\u0441\u0438\u043c \u043d\u0435 \u043e\u0448\u0438\u0431\u0441\u044f \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u0442\u043e \u041c\u0430\u043a\u0441\u0438\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0430 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439.<\/p>\n<p>  <\/p>\n<h2 id=\"varianty-zameny-rekursivnogo-algoritma\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043c\u0435\u043d\u044b \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/h2>\n<p>  <\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043c\u0435\u043d\u0451\u043d \u0446\u0438\u043a\u043b\u043e\u043c \u0438, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0435\u043a\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043b\u0443\u0447\u0448\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435. \u041d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"metod-todo-spiska\">\u041c\u0435\u0442\u043e\u0434 \u00abTODO-\u0441\u043f\u0438\u0441\u043a\u0430\u00bb<\/h2>\n<p>  <\/p>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0442\u0430\u043a\u0443\u044e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432 \u0444\u043e\u0440\u043c\u0435 \u0446\u0438\u043a\u043b\u0430. \u042f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043a\u0430\u043a \u0447\u0435\u0440\u0435\u0434\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u0441 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u0447\u0451\u0442 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/**  * factorial(n) returns n! for non-negative integer n  * if n &lt;= 18 it will be the exact value of the n!  * if n &lt;= 170 it will be approximate float value  * if n &gt;= 170 it will return Infinity  *\/ function factorial(n) {   if (n &lt;= 1) return 1   \/\/ TODO: Implement for non-trivial cases<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043a \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0442\u0435\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u00ab\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439\u00bb \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 <code>n &lt;= 1<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0448\u0438\u043c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u043b\u044f \u043d\u0435 \u00ab\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0445\u00bb \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0442\u0435\u043a \u043a\u043e\u043c\u0430\u043d\u0434 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u043b\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function factorial(n) {   if (n &lt;= 1) return 1;   let result = 0;   const todoStack = [];    \/\/ TODO: Plan some tasks    while (todoStack.length &gt; 0) {     const task = todoStack.pop();      \/\/ TODO: process the task   }    return result; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0426\u0438\u043a\u043b <code>while<\/code> \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>result<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b <code>N - 1<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b <code>N - 1<\/code> \u043d\u0430 <code>N<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u044d\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 <code>todoStack<\/code>. \u0422\u0430\u043a \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0435\u043a\u0435, \u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u044c \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function factorial(n) {   if (n &lt;= 1) return 1;    let result = 0;   const todoStack = [];    todoStack.push({ type: &quot;multiplyBy&quot;, multiplier: n });   todoStack.push({ type: &quot;calculteFactorial&quot;, value: n - 1 });    while (todoStack.length &gt; 0) {     const task = todoStack.pop();      \/\/ TODO: process the task   }    return result; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 \u0446\u0438\u043a\u043b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u0435\u043a \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function factorial(n) {   if (n &lt;= 1) return 1;    let result = 0;   const todoStack = [];    todoStack.push({ type: &quot;multiplyBy&quot;, multiplier: n });   todoStack.push({ type: &quot;calculateFactorial&quot;, value: n - 1 });    while (todoStack.length &gt; 0) {     const task = todoStack.pop();      if (task.type === &quot;multiplyBy&quot;) {       const { multiplier } = task;       result *= multiplier;       continue;     }      if (task.type === &quot;calculateFactorial&quot;) {       const { value } = task;        \/\/ \u00ab\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439\u00bb \u0441\u043b\u0443\u0447\u0430\u0439       if (value &lt;= 1) {         result = 1;         continue;       }        \/\/ \u041d\u0435 \u00ab\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439\u00bb, \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438.       todoStack.push({ type: &quot;multiplyBy&quot;, multiplier: value });       todoStack.push({ type: &quot;calculateFactorial&quot;, value: value - 1 });       continue;     }   }   return result; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0446\u0438\u043a\u043b\u043e\u043c <code>for<\/code>. \u041d\u043e \u043e\u043d \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0438\u0434\u0435\u044e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0435\u043a \u00ab\u0437\u0430\u0434\u0430\u0447\u00bb, \u0438 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044d\u0442\u043e\u0442 \u0441\u0442\u0435\u043a \u043e\u043f\u0443\u0441\u0442\u043e\u0448\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u044f \u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443.<\/p>\n<p>  <\/p>\n<h2 id=\"realnyy-primer-bolee-slozhnoy-rekursii\">\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u0421\u0435\u0440\u0433\u0435\u0439 \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c \u0438 \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u0438\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432. \u041e\u043d \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u043a\u0441\u0442. \u0418 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u0440\u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">type Parser&lt;T&gt; = (   input: string ) =&gt; Iterator&lt;[parsedValue: T, restString: string]&gt;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0432\u043e\u0442 \u043e\u043d \u0445\u043e\u0447\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>many1<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function many1&lt;T&gt;(parser: Parser&lt;T&gt;): Parser&lt;T[]&gt; {   \/\/ TODO: Write this function }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0441\u0435\u0440 \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437 \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0441\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const helloParser = function* (text) {   if (text.startsWith(&quot;hello&quot;)) {     yield [&quot;hello&quot;, text.slice(&quot;hello&quot;.length)];   } };  const many1HelloParser = many1(helloParser);  const parsed = [...many1HelloParser(&quot;hellohellohelloabc&quot;)];  \/* parsed = [     [['hello', 'hello', 'hello'], 'abc'],     [['hello', 'hello'], 'helloabc'],     [['hello'], 'hellohelloabc'], ] *\/<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"rekursiya\">\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0420\u0435\u0448\u0438\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function many1(parser) {   return function* (text) {     \/\/ \u0412\u044b\u0437\u043e\u0432\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438     yield* recMany1(parser, text, []);   }; }  \/\/ \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \/\/ - \u043f\u0430\u0440\u0441\u0435\u0440 \/\/ - \u0442\u0435\u043a\u0441\u0442, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \/\/ - \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 function* recMany1(parser, text, parsedValues) {   \/\/ \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043f\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c \u0438 \u0440\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445   for (const [parsed, restString] of parser(text)) {     const newParsedValues = [...parsedValues, parsed];     yield* recMany1(parser, restString, newParsedValues);   }    \/\/ \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c - \u0442\u043e \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442   if (parsedValues.length &gt; 0) {     yield [parsedValues, text];   } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"so-spiskom-zadach\">\u0421\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0437\u0430\u0434\u0430\u0447<\/h3>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0421\u0435\u0440\u0433\u0435\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0447\u0435\u0440\u0435\u0437 \u0446\u0438\u043a\u043b.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u043e\u043d \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function many1(parser) {   return function* (text) {     const tasksStack = [];      tasksStack.push({       type: &quot;iterate&quot;,       iterator: parser(text),       parsedValues: [],     });      while (tasksStack.length &gt; 0) {       const task = tasksStack.pop();        if (task.type === &quot;yield&quot;) {         \/\/ \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e         yield [task.parsedValues, task.restString];         continue;       }        if (task.type === &quot;iterate&quot;) {         \/\/ \u0418\u043c\u0435\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u043e \u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c         \/\/ \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430         const step = task.iterator.next();          \/\/ \u0415\u0441\u043b\u0438 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e. \u0422\u043e \u043d\u0435\u0447\u0435\u0433\u043e \u0438 \u0434\u0435\u043b\u0430\u0442\u044c         if (step.done) continue;          \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c         const [parsedValue, restString] = step.value;          \/\/ \u0417\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:         \/\/ 1. \u0420\u0435\u0448\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u043b\u044f restString         \/\/ 2. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0440\u0435\u0448\u0430\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438         \/\/ 3. \u0412\u044b\u0434\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u0430\u043a \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442          \/\/ 3         tasksStack.push({           type: &quot;yield&quot;,           parsedValues: [...task.parsedValues, parsedValue],           restString,         });          \/\/ 2         tasksStack.push(task);          \/\/ 1         tasksStack.push({           type: &quot;iterate&quot;,           iterator: parser(restString),           parsedValues: [...task.parsedValues, parsedValue],         });       }     }   }; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0430\u043b\u0430: \u0441\u0442\u0435\u043a \u0437\u0430\u0434\u0430\u0447, \u0438 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0445 \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u043a \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0432\u0438\u0434\u043e\u0432 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u044b\u0434\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/li>\n<li>\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0438\u0437 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u043f\u043e\u0442\u043e\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"posleslovie\">\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u042f \u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0441\u044f \u0441\u0432\u043e\u0438\u043c\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u00ab\u041c\u0430\u043a\u0441\u0438\u043c\u00bb \u0438\u043b\u0438 \u00ab\u0421\u0435\u0440\u0433\u0435\u0439\u00bb \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e \u0432 \u0446\u0438\u043a\u043b.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435, \u043a\u0430\u043a \u0432\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e \u0432 \u0446\u0438\u043a\u043b\u044b. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438? \u0418\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u043e\u043d\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b \u0431\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u0421\u0435\u0440\u0433\u0435\u044f \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043a\u0430\u043a? \u041f\u043e\u043f\u0430\u0434\u0430\u043b\u0438\u0441\u044c \u043b\u0438 \u0432\u0430\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0432 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445? \u0411\u044b\u043b\u0438 \u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0438, \u0433\u0434\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0438 Stack Overflow Error?<\/p>\n<p>  <\/p>\n<p>\u041e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0432\u0430\u0448 \u043e\u043f\u044b\u0442 \u0438 \u0432\u0430\u0448\u0435 \u043c\u043d\u0435\u043d\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430. \u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u0435\u0451 \u0440\u0435\u0448\u0438\u0442\u044c \u0431\u0435\u0437 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438, \u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e?<\/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\/533034\/\"> https:\/\/habr.com\/ru\/post\/533034\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u041c\u0430\u043a\u0441\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 Stack Overflow exception.<\/p>\n<p>  <\/p>\n<h2 id=\"zachem-maksim-eto-sdelal\">\u0417\u0430\u0447\u0435\u043c \u041c\u0430\u043a\u0441\u0438\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b?<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043b\u044e\u0431\u0438\u0442 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0438 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0435 \u043d\u0430 \u0435\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041e\u043d \u043d\u0435 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0438\u0448\u0435\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function factorial(n) {   let res = 1;   for (let i = 2; i &lt;= n; i++) {     res *= i;   }   return res; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043d \u0445\u043e\u0447\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const factorial = (n) =&gt; (n &gt; 1 ? n * factorial(n - 1) : 1);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u043d \u0432\u0438\u0434\u0438\u0442 \u044d\u0442\u043e:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mf\/6-\/hx\/mf6-hxx83m3v-llxd0opzgm2n0u.png\"><\/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-314859","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314859","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=314859"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314859\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}