Question Bank
/

JavaScript find vs filter for Student Lookup Quiz

JavaScript find vs filter for Student Lookup Quiz

Two seeded approaches to look up students by name: `find` returns the first match, `filter` returns every match. Two companions cover return-type pitfalls and short-circuit semantics.

Question Bank
Easy
JavaScript
4 questions
quiz
arrays
array-manipulation-patterns
fundamentals

807 views

20

Implement findStudentByName(students, name) using Array.prototype.find so it returns the first student object whose name matches, or undefined if none match.

Examples

Example 1:

Input: findStudentByName(students, 'jane')
Output: { name: 'jane', age: 34 }
Explanation: find walks left to right and returns the first matching element, so the older Jane is returned.
const students = [
    { name: 'john', age: 36 },
    { name: 'jane', age: 34 },
    { name: 'foo', age: 32 },
    { name: 'bar', age: 31 },
    { name: 'jane', age: 33 },
];

// implement findStudentByName with Array.prototype.find

console.log(findStudentByName(students, 'jane'));