From 7675b19f01250fa78bbce15f1dfb38d2226b7db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giftea=20=E2=98=95?= Date: Fri, 31 Oct 2025 21:24:59 +0100 Subject: [PATCH] feat(curriculum): Add interactive examples to Every and some methods lesson (#63392) --- .../673362e43d57b51f1ad2d466.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362e43d57b51f1ad2d466.md b/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362e43d57b51f1ad2d466.md index a7a96cd6ae2..2d363b0555f 100644 --- a/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362e43d57b51f1ad2d466.md +++ b/curriculum/challenges/english/blocks/lecture-working-with-higher-order-functions-and-callbacks/673362e43d57b51f1ad2d466.md @@ -5,7 +5,7 @@ challengeType: 19 dashedName: how-do-the-every-and-some-methods-work --- -# --description-- +# --interactive-- When you're working with arrays in JavaScript, there are often times when you want to check if all elements in an array meet a certain condition, or if at least one element meets a condition. @@ -17,6 +17,8 @@ The `every()` method returns `true` if the provided function returns `true` for Here's an example to illustrate how `every()` works: +:::interactive_editor + ```js const numbers = [2, 4, 6, 8, 10]; const hasAllEvenNumbers = numbers.every((num) => num % 2 === 0); @@ -24,6 +26,8 @@ const hasAllEvenNumbers = numbers.every((num) => num % 2 === 0); console.log(hasAllEvenNumbers); // true ``` +::: + In this example, we're checking if all numbers in the array are even. The function we provide to `every()` checks if each number is divisible by `2` with no remainder. Since all numbers in our array are indeed even, `hasAllEvenNumbers` will be true. Now, let's look at the `some()` method. @@ -32,6 +36,8 @@ While `every()` checks if all elements pass a test, `some()` checks if at least Here's an example of how `some()` works: +:::interactive_editor + ```js const numbers = [1, 3, 5, 7, 8, 9]; const hasSomeEvenNumbers = numbers.some((num) => num % 2 === 0); @@ -39,6 +45,8 @@ const hasSomeEvenNumbers = numbers.some((num) => num % 2 === 0); console.log(hasSomeEvenNumbers); // true ``` +::: + In this example, we're checking whether any number in the array is even. The function we pass to `some()` is the same as before. Even though most numbers in our array are odd, `hasEven` will be `true` because there's at least one even number (`8`) in the array. Both `every()` and `some()` are very useful when you need to validate data or check for certain conditions in your arrays. They can often replace more verbose loops and conditional statements, making your code cleaner and more expressive.