Bird
Raised Fist0
Javascriptprogramming~20 mins

Find and some methods in Javascript - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Find and Some Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of find method on array of objects
What is the output of the following code?
Javascript
const users = [
  { id: 1, name: 'Alice' },
  { id: 2, name: 'Bob' },
  { id: 3, name: 'Charlie' }
];

const result = users.find(user => user.id === 2);
console.log(result);
Aundefined
B{ id: 2, name: 'Bob' }
C{ id: 3, name: 'Charlie' }
D[{ id: 2, name: 'Bob' }]
Attempts:
2 left
πŸ’‘ Hint
The find method returns the first element that matches the condition.
❓ Predict Output
intermediate
2:00remaining
Output of some method with condition
What does the following code output?
Javascript
const numbers = [1, 3, 5, 7, 8];
const hasEven = numbers.some(num => num % 2 === 0);
console.log(hasEven);
Atrue
Bfalse
Cundefined
DTypeError
Attempts:
2 left
πŸ’‘ Hint
The some method returns true if any element matches the condition.
❓ Predict Output
advanced
2:00remaining
Find method with no matching element
What is the output of this code?
Javascript
const fruits = ['apple', 'banana', 'cherry'];
const found = fruits.find(fruit => fruit.length > 10);
console.log(found);
Anull
B'' (empty string)
Cundefined
DTypeError
Attempts:
2 left
πŸ’‘ Hint
If find does not find any element, it returns undefined.
❓ Predict Output
advanced
2:00remaining
Some method with all elements failing condition
What will this code output?
Javascript
const ages = [21, 25, 30];
const hasMinor = ages.some(age => age < 18);
console.log(hasMinor);
ASyntaxError
Btrue
Cundefined
Dfalse
Attempts:
2 left
πŸ’‘ Hint
some returns false if no elements satisfy the condition.
🧠 Conceptual
expert
3:00remaining
Understanding behavior of find and some with complex conditions
Given the code below, what is the output of the console.log statement?
Javascript
const data = [
  { id: 1, active: false },
  { id: 2, active: false },
  { id: 3, active: true },
  { id: 4, active: true }
];

const result = data.find(item => item.active && item.id > 3);
const check = data.some(item => item.active && item.id <= 3);
console.log(result, check);
A{ id: 4, active: true } true
B{ id: 3, active: true } false
Cundefined true
Dundefined false
Attempts:
2 left
πŸ’‘ Hint
find returns the first element matching the condition; some returns true if any element matches.

Practice

(1/5)
1. What does the find method do in JavaScript arrays?
easy
A. Returns the first element that matches a condition or undefined if none
B. Returns true if all elements match a condition
C. Returns the index of the last matching element
D. Returns a new array with elements that match a condition

Solution

  1. Step 1: Understand the purpose of find

    The find method searches an array and returns the first element that satisfies the given condition.
  2. Step 2: Compare with other methods

    Unlike filter which returns all matching elements, find returns only the first or undefined if none found.
  3. Final Answer:

    Returns the first element that matches a condition or undefined if none -> Option A
  4. Quick Check:

    find returns first match [OK]
Hint: Remember: find returns one item, some returns true/false [OK]
Common Mistakes:
  • Confusing find with filter
  • Thinking find returns a boolean
  • Assuming find returns all matches
2. Which of the following is the correct syntax to use some on an array arr to check if any element is greater than 10?
easy
A. arr.some(x > 10);
B. arr.some(x => x > 10);
C. arr.some(x => {x > 10});
D. arr.some(x => x > 10) {};

Solution

  1. Step 1: Identify correct arrow function syntax

    The some method requires a function that returns true or false. The arrow function x => x > 10 correctly returns a boolean.
  2. Step 2: Check syntax errors in options

    arr.some(x > 10); misses the arrow function syntax. arr.some(x => {x > 10}); uses braces but no return statement, so returns undefined. arr.some(x => x > 10) {}; has extra braces after the method call, which is invalid.
  3. Final Answer:

    arr.some(x => x > 10); -> Option B
  4. Quick Check:

    Arrow function with return expression [OK]
Hint: Use arrow function with expression for some() [OK]
Common Mistakes:
  • Missing arrow in arrow function
  • Using braces without return in arrow function
  • Adding extra braces after method call
3. What is the output of this code?
const numbers = [3, 7, 12, 5];
const result = numbers.find(n => n > 10);
console.log(result);
medium
A. 7
B. undefined
C. 3
D. 12

Solution

  1. Step 1: Understand the find condition

    The condition n > 10 looks for the first number greater than 10 in the array.
  2. Step 2: Check array elements in order

    The array is [3, 7, 12, 5]. The first element > 10 is 12.
  3. Final Answer:

    12 -> Option D
  4. Quick Check:

    First number > 10 is 12 [OK]
Hint: Find returns first match, not all matches [OK]
Common Mistakes:
  • Thinking find returns all matches
  • Confusing find with some
  • Choosing first element instead of first matching
4. The following code does not work as expected. What is the problem?
const arr = [1, 2, 3];
const hasEven = arr.some(n => { n % 2 === 0 });
console.log(hasEven);
medium
A. The condition should use == instead of ===
B. The some method is not available on arrays
C. The arrow function does not return a value
D. The array is empty

Solution

  1. Step 1: Analyze arrow function body

    The arrow function uses braces but no return statement, so it returns undefined.
  2. Step 2: Understand some expects boolean return

    Since the function returns undefined, some cannot check the condition properly, causing unexpected behavior.
  3. Final Answer:

    The arrow function does not return a value -> Option C
  4. Quick Check:

    Arrow function with braces needs explicit return [OK]
Hint: Use return inside braces or remove braces in arrow function [OK]
Common Mistakes:
  • Forgetting return in arrow function with braces
  • Thinking some is not an array method
  • Confusing equality operators
5. Given an array of user objects:
const users = [
  { id: 1, active: false },
  { id: 2, active: true },
  { id: 3, active: false }
];
Which code correctly finds the first active user and checks if any user is active?
hard
A. const firstActive = users.find(u => u.active); const anyActive = users.some(u => u.active);
B. const firstActive = users.some(u => u.active); const anyActive = users.find(u => u.active);
C. const firstActive = users.filter(u => u.active)[0]; const anyActive = users.find(u => u.active);
D. const firstActive = users.find(u => u.active === false); const anyActive = users.some(u => u.active === false);

Solution

  1. Step 1: Find first active user

    The find method returns the first user object where active is true.
  2. Step 2: Check if any user is active

    The some method returns true if any user has active true.
  3. Final Answer:

    const firstActive = users.find(u => u.active); const anyActive = users.some(u => u.active); -> Option A
  4. Quick Check:

    find returns object, some returns boolean [OK]
Hint: Use find for first match, some for boolean check [OK]
Common Mistakes:
  • Swapping find and some usage
  • Using filter instead of find for first element
  • Checking for false instead of true
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard