File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 2626
2727 // Some and Every Checks
2828 // Array.prototype.some() // is at least one person 19?
29+ const isAdult = people . some ( person => {
30+ const currYear = ( new Date ( ) ) . getFullYear ( )
31+ return ( currYear - person . year ) >= 19
32+ } )
33+
34+ // One liner
35+ const isAdult2 = people . some ( ( { year} ) => ( ( new Date ( ) ) . getFullYear ( ) - year ) >= 19 )
36+
2937 // Array.prototype.every() // is everyone 19?
38+ const everyAdult = people . every ( ( { year} ) => ( ( new Date ( ) ) . getFullYear ( ) - year ) >= 19 )
3039
3140 // Array.prototype.find()
3241 // Find is like filter, but instead returns just the one you are looking for
3342 // find the comment with the ID of 823423
34-
43+ const cID = 823423
44+ const comment = comments . find ( ( { id} ) => id === cID )
45+
3546 // Array.prototype.findIndex()
3647 // Find the comment with this ID
3748 // delete the comment with the ID of 823423
49+ const index = comments . findIndex ( ( { id} ) => id === cID )
50+ const newComments = [
51+ ...comments . splice ( 0 , index ) ,
52+ ...comments . splice ( index + 1 )
53+ ]
3854
3955 </ script >
4056</ body >
You can’t perform that action at this time.
0 commit comments