Array.every II - objects

Easy
2
66.7% Acceptance

In this coding challenge, you will be implementing a function called validateObject(users) that takes an array of users as the input. Assume that every user is an object. The function should check if every user object in the array users has the property firstName.

Instructions

  • If the input array is empty, return false.

Example test cases

1const users1 = [ 2 { firstName: 'John', lastName: 'Doe' }, 3 { firstName: 'Jane', lastName: 'Doe' }, 4]; 5validateObject(users1); // Output: true 6 7const users2 = [ 8 { firstName: 'John', lastName: 'Doe' }, 9 { lastName: 'Doe' }, 10]; 11validateObject(users2); // Output: false

Hints

  • You can use the built-in method .every() directly on the input array.
  • Alternatively, you can write a for loop that iterates over every element of the array and checks if each element is a string.