Challenge - 5 Problems
Find and Some Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediateOutput 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);
Attempts:
2 left
π‘ Hint
The find method returns the first element that matches the condition.
β Incorrect
The find method returns the first object where user.id equals 2, which is { id: 2, name: 'Bob' }.
β Predict Output
intermediateOutput 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);
Attempts:
2 left
π‘ Hint
The some method returns true if any element matches the condition.
β Incorrect
The array contains 8, which is even, so some returns true.
β Predict Output
advancedFind 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);
Attempts:
2 left
π‘ Hint
If find does not find any element, it returns undefined.
β Incorrect
No fruit has length greater than 10, so find returns undefined.
β Predict Output
advancedSome 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);
Attempts:
2 left
π‘ Hint
some returns false if no elements satisfy the condition.
β Incorrect
No age is less than 18, so some returns false.
π§ Conceptual
expertUnderstanding 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);
Attempts:
2 left
π‘ Hint
find returns the first element matching the condition; some returns true if any element matches.
β Incorrect
find looks for active true and id > 3, which is { id: 4, active: true }. some checks if any active true with id <= 3, which is { id: 3, active: true }, so true.
