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.