File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 2525
2626 // Some and Every Checks
2727 // 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 ( ) )
36+ . getFullYear ( ) ) - person . year >= 19 ) ;
37+
38+ console . log ( { isAdult} ) ;
2839 // Array.prototype.every() // is everyone 19?
2940
41+ const allAdults = people . every ( person => ( ( new Date ( ) )
42+ . getFullYear ( ) ) - person . year >= 19 ) ;
43+
44+ console . log ( { allAdults} ) ;
3045 // Array.prototype.find()
3146 // Find is like filter, but instead returns just the one you are looking for
3247 // find the comment with the ID of 823423
3348
49+ const comment = comments . find ( comment =>
50+ comment . id === 823423 ) ;
51+
52+ console . log ( comment ) ;
3453 // Array.prototype.findIndex()
3554 // Find the comment with this ID
3655 // delete the comment with the ID of 823423
3756
57+ const index = comments . findIndex ( comment =>
58+ comment . id === 823423 ) ;
59+
60+ console . log ( { index} ) ;
61+
62+ // comments.splice(index, 1);
63+
64+ const newComments = [
65+ ...comments . slice ( 0 , index ) ,
66+ ...comments . slice ( index + 1 )
67+ ] ;
68+
3869 </ script >
3970</ body >
4071</ html >
You can’t perform that action at this time.
0 commit comments