From 0ef0992514bdee32d4e719dc8af6228faee4a2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giftea=20=E2=98=95?= Date: Fri, 31 Oct 2025 21:29:07 +0100 Subject: [PATCH] feat(curriculum): Add interactive examples to Reduce method lesson (#63402) --- .../673362be2f70c21e65bc5459.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362be2f70c21e65bc5459.md b/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362be2f70c21e65bc5459.md index 221bbe285c4..11ed842abab 100644 --- a/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362be2f70c21e65bc5459.md +++ b/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362be2f70c21e65bc5459.md @@ -5,7 +5,7 @@ challengeType: 19 dashedName: what-is-the-reduce-method-and-how-does-it-work --- -# --description-- +# --interactive-- The `reduce` method is a function in JavaScript that allows you to process an array and condense it into a single value. This single value can be a number, a string, an object, or even another array. @@ -17,6 +17,8 @@ The reducer function takes two main parameters: an accumulator and the current v Let's look at an example to illustrate how `reduce` works: +:::interactive_editor + ```js const numbers = [1, 2, 3, 4, 5]; const sum = numbers.reduce( @@ -27,6 +29,8 @@ const sum = numbers.reduce( console.log(sum); // 15 ``` +::: + In this example, we're using `reduce` to get the sum of all the numbers in the array. The reducer function takes the accumulator (which starts at `0`, as specified by the second argument to `reduce`) and adds each number to it.