{"id":331,"date":"2026-06-26T13:34:40","date_gmt":"2026-06-26T13:34:40","guid":{"rendered":"https:\/\/aabbee.cafe24.com\/?p=331"},"modified":"2026-06-26T13:34:40","modified_gmt":"2026-06-26T13:34:40","slug":"reduce","status":"publish","type":"post","link":"https:\/\/coalacoding.com\/?p=331","title":{"rendered":"reduce"},"content":{"rendered":"<p>\uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\uc758 <code>reduce()<\/code> \ud568\uc218\ub294 \ubc30\uc5f4\uc758 \uac01 \uc694\uc18c\uc5d0 \ub300\ud574 \uc8fc\uc5b4\uc9c4 \ub9ac\ub4c0\uc11c(reducer) \ud568\uc218\ub97c \uc2e4\ud589\ud558\uace0, \ud558\ub098\uc758 \uacb0\uacfc\uac12\uc744 \ubc18\ud658\ud558\ub294 \uac15\ub825\ud55c \ubc30\uc5f4 \uba54\uc11c\ub4dc\uc785\ub2c8\ub2e4.<\/p>\n<p>\uae30\ubcf8 \uad6c\ubb38<\/p>\n<pre><code class=\"language-javascript\">arr.reduce((accumulator, currentValue, currentIndex, array) =&gt; {\n\/\/ \ub9ac\ub4c0\uc11c \ud568\uc218 \ub85c\uc9c1\n}, initialValue)\n<\/code><\/pre>\n<ol>\n<li>\uae30\ubcf8\uc801\uc778 \uc22b\uc790 \ud569\uacc4 \uacc4\uc0b0:<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\">\nconst numbers = [1, 2, 3, 4, 5];\nconst sum = numbers.reduce((acc, current) =&gt; acc + current, 0);\nconsole.log(sum); \/\/ 15\n<\/code><\/pre>\n<ol>\n<li>\uac1d\uccb4 \ubc30\uc5f4\uc5d0\uc11c \uc18d\uc131 \uac12 \ud569\uc0b0:<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\">\nconst products = [\n  { name: &#39;\uc0ac\uacfc&#39;, price: 1000 },\n  { name: &#39;\ubc14\ub098\ub098&#39;, price: 1500 },\n  { name: &#39;\uc624\ub80c\uc9c0&#39;, price: 2000 }\n];\nconst totalPrice = products.reduce((acc, product) =&gt; acc + product.price, 0);\nconsole.log(totalPrice); \/\/ 4500\n<\/code><\/pre>\n<ol>\n<li>\ubc30\uc5f4\uc744 \uac1d\uccb4\ub85c \ubcc0\ud658:<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\">\nconst fruits = [&#39;\uc0ac\uacfc&#39;, &#39;\ubc14\ub098\ub098&#39;, &#39;\uc0ac\uacfc&#39;, &#39;\uc624\ub80c\uc9c0&#39;, &#39;\ubc14\ub098\ub098&#39;];\nconst fruitCount = fruits.reduce((acc, fruit) =&gt; {\n  acc[fruit] = (acc[fruit] || 0) + 1;\n  return acc;\n}, {});\nconsole.log(fruitCount);\n\/\/ { &#39;\uc0ac\uacfc&#39;: 2, &#39;\ubc14\ub098\ub098&#39;: 2, &#39;\uc624\ub80c\uc9c0&#39;: 1 }\n<\/code><\/pre>\n<p><code>reduce()<\/code> \ud568\uc218\uc758 \ub9e4\uac1c\ubcc0\uc218:<\/p>\n<ul>\n<li><code>accumulator<\/code>: \ub204\uc0b0\uae30, \ub204\uc801\ub41c \uacc4\uc0b0 \uacb0\uacfc<\/li>\n<li><code>currentValue<\/code>: \ud604\uc7ac \ucc98\ub9ac\ub418\ub294 \ubc30\uc5f4 \uc694\uc18c<\/li>\n<li><code>currentIndex<\/code>: \ud604\uc7ac \uc694\uc18c\uc758 \uc778\ub371\uc2a4 (\uc120\ud0dd\uc801)<\/li>\n<li><code>array<\/code>: \uc6d0\ubcf8 \ubc30\uc5f4 (\uc120\ud0dd\uc801)<br \/>\n\uc911\uc694\ud55c \ud2b9\uc9d5:<\/li>\n<li>\ucd08\uae30\uac12(initialValue)\uc744 \uc81c\uacf5\ud558\uc9c0 \uc54a\uc73c\uba74, \ubc30\uc5f4\uc758 \uccab \ubc88\uc9f8 \uc694\uc18c\uac00 \ucd08\uae30\uac12\uc774 \ub429\ub2c8\ub2e4.<\/li>\n<li>\ube48 \ubc30\uc5f4\uc5d0\uc11c \ucd08\uae30\uac12 \uc5c6\uc774 \ud638\ucd9c\ud558\uba74 \uc624\ub958\uac00 \ubc1c\uc0dd\ud569\ub2c8\ub2e4.<br \/>\n<code>reduce()<\/code>\ub294 \ubc30\uc5f4\uc744 \ub2e8\uc77c \uac12\uc73c\ub85c \uc904\uc774\uac70\ub098 \ubcf5\uc7a1\ud55c \ubcc0\ud658\uc744 \uc218\ud589\ud558\ub294 \ub370 \ub9e4\uc6b0 \uc720\uc6a9\ud55c \uba54\uc11c\ub4dc\uc785\ub2c8\ub2e4. \ud569\uacc4 \uacc4\uc0b0, \ud3c9\uade0 \uad6c\ud558\uae30, \uac1d\uccb4 \uadf8\ub8f9\ud654 \ub4f1 \ub2e4\uc591\ud55c \uc0c1\ud669\uc5d0\uc11c \ud65c\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\uc758 reduce() \ud568\uc218\ub294 \ubc30\uc5f4\uc758 \uac01 \uc694\uc18c\uc5d0 \ub300\ud574 \uc8fc\uc5b4\uc9c4 \ub9ac\ub4c0\uc11c(reducer) \ud568\uc218\ub97c \uc2e4\ud589\ud558\uace0, \ud558\ub098\uc758 \uacb0\uacfc\uac12\uc744 \ubc18\ud658\ud558\ub294 \uac15\ub825\ud55c \ubc30\uc5f4 \uba54\uc11c\ub4dc\uc785\ub2c8\ub2e4. \uae30\ubcf8 \uad6c\ubb38 arr.reduce((accumulator, currentValue, currentIndex, array) =&gt; { \/\/ \ub9ac\ub4c0\uc11c \ud568\uc218 \ub85c\uc9c1 }, initialValue) \uae30\ubcf8\uc801\uc778 \uc22b\uc790 \ud569\uacc4 \uacc4\uc0b0: const numbers = [1, 2, 3, 4, 5]; const sum = numbers.reduce((acc, current) =&gt; acc + current, 0); console.log(sum); \/\/ &#8230; <a title=\"reduce\" class=\"read-more\" href=\"https:\/\/coalacoding.com\/?p=331\" aria-label=\"reduce\uc5d0 \ub300\ud574 \ub354 \uc790\uc138\ud788 \uc54c\uc544\ubcf4\uc138\uc694\">\ub354 \uc77d\uae30<\/a><\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-331","post","type-post","status-publish","format-standard","hentry","category-javascript-basics"],"_links":{"self":[{"href":"https:\/\/coalacoding.com\/index.php?rest_route=\/wp\/v2\/posts\/331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coalacoding.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coalacoding.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/coalacoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=331"}],"version-history":[{"count":0,"href":"https:\/\/coalacoding.com\/index.php?rest_route=\/wp\/v2\/posts\/331\/revisions"}],"wp:attachment":[{"href":"https:\/\/coalacoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coalacoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coalacoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}