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