Skip to content

Commit 9aa11ab

Browse files
committed
finish array cardio wesbos#2
1 parent 68d38c3 commit 9aa11ab

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

07 - Array Cardio Day 2/index-START.html

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,40 @@
1717
];
1818

1919
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 },
2424
{ text: 'Nice Nice Nice!', id: 542328 }
2525
];
2626

2727
// Some and Every Checks
28+
2829
// 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+
2933
// 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)
3036

3137
// Array.prototype.find()
3238
// Find is like filter, but instead returns just the one you are looking for
3339
// find the comment with the ID of 823423
40+
const foundCommentById = comments.find((comment) => comment.id === 823423)
41+
console.log("foundCommentById", foundCommentById)
3442

3543
// Array.prototype.findIndex()
3644
// Find the comment with this ID
45+
const foundCommentIndex = comments.findIndex((comment) => comment.id === 823423)
46+
console.log("foundCommentIndex", foundCommentIndex)
47+
3748
// 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)
3854

3955
</script>
4056
</body>

0 commit comments

Comments
 (0)