File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-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?
29
+ const currentYear = ( new Date ( ) ) . getFullYear ( ) ;
30
+ const someAreNineteen = people . some ( person => currentYear - person . year >= 19 ) ;
31
+ console . log ( 'Someone is 19' , someAreNineteen ) ;
29
32
// Array.prototype.every() // is everyone 19?
33
+ const allAreNineteen = people . every ( person => currentYear - person . year >= 19 ) ;
34
+ console . log ( 'All are 19' , allAreNineteen ) ;
30
35
31
36
// Array.prototype.find()
32
37
// Find is like filter, but instead returns just the one you are looking for
33
38
// find the comment with the ID of 823423
39
+ const theFoundComment = comments . find ( comment => comment . id === 823423 ) ;
40
+ console . log ( 'The found comment:' , theFoundComment ) ;
34
41
35
42
// Array.prototype.findIndex()
36
43
// Find the comment with this ID
37
44
// delete the comment with the ID of 823423
45
+ const theIndex = comments . findIndex ( comment => comment . id === 823423 ) ;
46
+ console . log ( 'Comments before' ) ;
47
+ console . table ( comments ) ;
48
+ const newComments = [
49
+ ...comments . slice ( 0 , theIndex ) ,
50
+ ...comments . slice ( theIndex + 1 )
51
+ ] ;
52
+ console . log ( 'Comments after' ) ;
53
+ console . table ( newComments ) ;
38
54
39
55
</ script >
40
56
</ body >
You can’t perform that action at this time.
0 commit comments