File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 2626
2727 // Some and Every Checks
2828 // Array.prototype.some() // is at least one person 19 or older?
29+ const isAdult = people . some ( ( person ) => {
30+ const currentYear = ( new Date ( ) ) . getFullYear ( ) ;
31+ return currentYear - person . year >= 19
32+ } ) ;
33+ console . log ( 'At least one perso is 19 or older: ' + isAdult ) ;
34+
2935 // Array.prototype.every() // is everyone 19 or older?
36+ const areAllAdults = people . every ( ( person ) => {
37+ const currentYear = ( new Date ( ) ) . getFullYear ( ) ;
38+ return currentYear - person . year >= 19
39+ } )
40+ console . log ( 'Is everyone an adult: ' + areAllAdults ) ;
3041
3142 // Array.prototype.find()
3243 // Find is like filter, but instead returns just the one you are looking for
3344 // find the comment with the ID of 823423
45+ const comment = comments . find ( comment => comment . id === 823423 ) ;
46+ console . log ( comment ) ;
3447
3548 // Array.prototype.findIndex()
3649 // Find the comment with this ID
3750 // delete the comment with the ID of 823423
51+ const index = comments . findIndex ( comment => comment . id === 823423 ) ;
52+ const newComments = [
53+ ...comments . slice ( 0 , index ) ,
54+ ...comments . slice ( index + 1 )
55+ ]
56+ console . table ( newComments ) ;
3857
3958 </ script >
4059</ body >
You can’t perform that action at this time.
0 commit comments