|
17 | 17 | ];
|
18 | 18 |
|
19 | 19 | const comments = [
|
20 |
| - { text: 'Love this!', id: 523423 }, |
21 |
| - { text: 'Super good', id: 823423 }, |
22 |
| - { text: 'You are the best', id: 2039842 }, |
23 |
| - { text: 'Ramen is my fav food ever', id: 123523 }, |
| 20 | + { text: 'Love this!', id: 523423 }, |
| 21 | + { text: 'Super good', id: 823423 }, |
| 22 | + { text: 'You are the best', id: 2039842 }, |
| 23 | + { text: 'Ramen is my fav food ever', id: 123523 }, |
24 | 24 | { text: 'Nice Nice Nice!', id: 542328 }
|
25 | 25 | ];
|
26 | 26 |
|
27 | 27 | // Some and Every Checks
|
| 28 | + |
28 | 29 | // Array.prototype.some() // is at least one person 19 or older?
|
| 30 | + const isAnybodyOverNineteenYearsOld = people.some(person => person.year - (new Date().getFullYear()) >= 19) |
| 31 | + console.log("isAnybodyOverNineteenYearsOld", isAnybodyOverNineteenYearsOld) |
| 32 | + |
29 | 33 | // Array.prototype.every() // is everyone 19 or older?
|
| 34 | + const isEveryoneOverNineteenYearsOld = people.every(person => person.year - (new Date().getFullYear()) >= 19) |
| 35 | + console.log("isEveryoneOverNineteenYearsOld", isEveryoneOverNineteenYearsOld) |
30 | 36 |
|
31 | 37 | // Array.prototype.find()
|
32 | 38 | // Find is like filter, but instead returns just the one you are looking for
|
33 | 39 | // find the comment with the ID of 823423
|
| 40 | + const foundCommentById = comments.find((comment) => comment.id === 823423) |
| 41 | + console.log("foundCommentById", foundCommentById) |
34 | 42 |
|
35 | 43 | // Array.prototype.findIndex()
|
36 | 44 | // Find the comment with this ID
|
| 45 | + const foundCommentIndex = comments.findIndex((comment) => comment.id === 823423) |
| 46 | + console.log("foundCommentIndex", foundCommentIndex) |
| 47 | + |
37 | 48 | // delete the comment with the ID of 823423
|
| 49 | + const newComments = [ |
| 50 | + ...comments.slice(0, foundCommentIndex), |
| 51 | + ...comments.slice(foundCommentIndex + 1) |
| 52 | + ]; |
| 53 | + console.log("newComments", newComments) |
38 | 54 |
|
39 | 55 | </script>
|
40 | 56 | </body>
|
|
0 commit comments