array.some function checking if someone in a list is over 18

Array of objects to work with:

    const people = [
      { name: 'Wes', year: 1988 },
      { name: 'Kait', year: 1986 },
      { name: 'Irv', year: 1970 },
      { name: 'Lux', year: 2015 }
    ];

Array.prototype.some() // is at least one person 19 or older?

    const isAdult = people.some(function(person){
        const currentYear = new Date().getFullYear();
        if(currentYear - person.year >= 19){
          return true;
        }
    });

refactored with an array function

    const isAdult = people.some(person => {
        return new Date().getFullYear() - person.year >= 19;
    });

//refactored

  const isAdult = people.some(person => new Date().getFullYear() - person.year >= 19);

Add your comment