File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 27
27
28
28
// Some and Every Checks
29
29
// Array.prototype.some() // is at least one person 19 or older?
30
+ // const isAdult = people.some(function(person) {
31
+ // const currentYear = (new Date()).getFullYear();
32
+ // if (currentYear - person.year){
33
+ // return true;
34
+ // }
35
+ // });
36
+
37
+ const isAdult = people . some ( person => ( new Date ( ) ) . getFullYear ( ) - person . year >= 19 ) ;
38
+ console . log ( isAdult ) ;
30
39
// Array.prototype.every() // is everyone 19 or older?
40
+ const allAdults = people . every ( person => ( new Date ( ) ) . getFullYear ( ) - person . year >= 19 ) ;
41
+ console . log ( allAdults ) ;
31
42
32
43
// Array.prototype.find()
33
44
// Find is like filter, but instead returns just the one you are looking for
34
45
// find the comment with the ID of 823423
35
46
47
+ const comment = comments . find ( comment => comment . id === 823423 ) ;
48
+ console . log ( comment ) ;
49
+
36
50
// Array.prototype.findIndex()
37
51
// Find the comment with this ID
38
52
// delete the comment with the ID of 823423
39
53
54
+ const index = comments . findIndex ( comment => comment . id === 823423 ) ;
55
+ comments . splice ( index , 1 ) ;
56
+ console . log ( comments ) ;
57
+
40
58
</ script >
41
59
</ body >
42
60
</ html >
You can’t perform that action at this time.
0 commit comments