11<!DOCTYPE html>
22< html lang ="en ">
3+
34< head >
45 < meta charset ="UTF-8 ">
56 < title > Array Cardio 💪💪</ title >
67</ head >
8+
79< body >
8- < p > < em > Psst: have a look at the JavaScript Console</ em > 💁</ p >
10+ < p >
11+ < em > Psst: have a look at the JavaScript Console</ em > 💁</ p >
912 < script >
1013 // ## Array Cardio Day 2
1114
2730 // Some and Every Checks
2831 // Array.prototype.some() // is at least one person 19 or older?
2932 // Array.prototype.every() // is everyone 19 or older?
33+ const now = new Date ( ) ;
34+ const year = now . getFullYear ( ) ;
35+ const isSomeOlder = people . some ( person => year - person . year >= 19 ) ;
36+ const isEveryOlder = people . every ( person => year - person . year >= 19 ) ;
37+ console . log ( isSomeOlder , isEveryOlder ) ;
3038
3139 // Array.prototype.find()
3240 // Find is like filter, but instead returns just the one you are looking for
3341 // find the comment with the ID of 823423
42+ const found = comments . find ( comment => comment . id === 823423 ) ;
43+ console . log ( found ) ;
3444
3545 // Array.prototype.findIndex()
3646 // Find the comment with this ID
3747 // delete the comment with the ID of 823423
48+ const foundIndex = comments . findIndex ( comment => comment . id === 823423 ) ;
49+ console . log ( foundIndex ) ;
50+
51+ // comments.splice(foundIndex, 1);
3852
53+ const newComments = [
54+ ...comments . slice ( 0 , foundIndex ) ,
55+ ...comments . slice ( foundIndex + 1 )
56+ ] ;
57+
58+ console . log ( comments , newComments ) ;
3959 </ script >
4060</ body >
41- </ html >
61+
62+ </ html >
0 commit comments