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 26
26
27
27
// Some and Every Checks
28
28
// 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
+
29
35
// 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 ) ;
30
41
31
42
// Array.prototype.find()
32
43
// Find is like filter, but instead returns just the one you are looking for
33
44
// find the comment with the ID of 823423
45
+ const comment = comments . find ( comment => comment . id === 823423 ) ;
46
+ console . log ( comment ) ;
34
47
35
48
// Array.prototype.findIndex()
36
49
// Find the comment with this ID
37
50
// 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 ) ;
38
57
39
58
</ script >
40
59
</ body >
You can’t perform that action at this time.
0 commit comments