Saturday, January 7, 2017

JS30 Challenge Day 7 - Array workout #2


.some
checks at least one thing in the array matches something

getFullYear() is a function, not a property, of Date

find is like filter but instead of returning a subset of the array it returns the first item it finds

A handy way to use {}
console.log(allAdult) gives us the value of allAdult variable
console.log({allAdult}) gives us the allAdult object itself

A great way to use =>

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

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

Reminded me of the Array.splice function.
Example of splice:

b=c.splice(3,2); //starting from index 3, remove 2 elements and    //place them in b

No comments:

Post a Comment