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 29
29
// Array.prototype.some() // is at least one person 19 or older?
30
30
// Array.prototype.every() // is everyone 19 or older?
31
31
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
+
32
48
// Array.prototype.find()
33
49
// Find is like filter, but instead returns just the one you are looking for
34
50
// find the comment with the ID of 823423
35
51
52
+ const found = comments . find ( element => element . id === 823423 )
53
+ console . log ( found )
54
+
55
+
56
+
36
57
// Array.prototype.findIndex()
37
58
// Find the comment with this ID
38
59
// 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 )
39
64
40
65
</ script >
41
66
</ body >
You can’t perform that action at this time.
0 commit comments