File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 2929 // Array.prototype.some() // is at least one person 19 or older?
3030 // Array.prototype.every() // is everyone 19 or older?
3131
32+ const isAdult = people . some ( person => {
33+ const currentYear = ( new Date ( ) . getFullYear ( ) ) ;
34+ if ( currentYear - person . year >= 19 ) {
35+ return true ;
36+ }
37+ } )
38+ console . log ( { isAdult} )
39+
40+ const allAdult = people . every ( person => {
41+ const currentYear = ( new Date ( ) . getFullYear ( ) ) ;
42+ if ( currentYear - person . year >= 19 ) {
43+ return true ;
44+ }
45+ } )
46+ console . log ( { allAdult} )
47+
3248 // Array.prototype.find()
3349 // Find is like filter, but instead returns just the one you are looking for
3450 // find the comment with the ID of 823423
3551
52+ const found = comments . find ( element => element . id === 823423 )
53+ console . log ( found )
54+
55+
56+
3657 // Array.prototype.findIndex()
3758 // Find the comment with this ID
3859 // delete the comment with the ID of 823423
60+ const index = comments . findIndex ( comment => comment . id === 823423 ) ;
61+ console . log ( found )
62+ comments . splice ( index , 1 ) ;
63+ console . log ( comments )
3964
4065 </ script >
4166</ body >
You can’t perform that action at this time.
0 commit comments