File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 2727
2828 // Some and Every Checks
2929 // Array.prototype.some() // is at least one person 19 or older?
30+ // const isAdult = people.some((person) => {
31+ // const currentYear = new Date().getFullYear();
32+ // if (currentYear - person.year >= 19) {
33+ // return true;
34+ // }
35+ // });
36+
37+ const isAdult = people . some ( ( person ) => ( new Date ( ) . getFullYear ( ) - person . year ) >= 19 ) ;
38+ console . log ( { isAdult} ) ;
3039 // Array.prototype.every() // is everyone 19 or older?
40+ const allAdults = people . every ( ( person ) => ( new Date ( ) . getFullYear ( ) - person . year ) >= 19 ) ;
41+ console . log ( { allAdults} ) ;
3142
3243 // Array.prototype.find()
3344 // Find is like filter, but instead returns just the one you are looking for
3445 // find the comment with the ID of 823423
46+ const comment = comments . find ( ( comment ) => comment . id === 823423 ) ;
47+ console . log ( comment ) ;
3548
3649 // Array.prototype.findIndex()
3750 // Find the comment with this ID
3851 // delete the comment with the ID of 823423
52+ const index = comments . findIndex ( ( index ) => index . id === 823423 ) ;
53+ console . log ( index ) ;
54+ // comments.splice(index, 1);
55+ // console.log(comments);
56+
57+ const newComments = [
58+ ...comments . slice ( 0 , index ) ,
59+ ...comments . slice ( index + 1 )
60+ ] ;
61+ console . log ( newComments ) ;
3962
4063 </ script >
4164</ body >
You can’t perform that action at this time.
0 commit comments