Visitar URL original
Adds Day 7 Finished Code. · wesbos/JavaScript30@c6d0adb · GitHub
Skip to content

Commit c6d0adb

Browse files
Adds Day 7 Finished Code.
1 parent f68d7aa commit c6d0adb

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,42 @@
2626

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19?
29+
const isAdult = people.some(person => {
30+
const currentYear = (new Date()).getFullYear();
31+
return currentYear - person.year >= 19;
32+
});
33+
34+
console.log({isAdult});
35+
2936
// Array.prototype.every() // is everyone 19?
37+
const isEveryoneAdult = people.every(person => {
38+
const currentYear = (new Date()).getFullYear();
39+
return currentYear - person.year >= 19;
40+
});
41+
42+
console.log({ isEveryoneAdult });
3043

3144
// Array.prototype.find()
3245
// Find is like filter, but instead returns just the one you are looking for
3346
// find the comment with the ID of 823423
47+
const comment = comments.find(comment => comment.id === 823423);
48+
49+
console.log({comment});
3450

3551
// Array.prototype.findIndex()
3652
// Find the comment with this ID
3753
// delete the comment with the ID of 823423
54+
const commentIndex = comments.findIndex(comment => comment.id === 823423);
55+
56+
console.log(commentIndex);
57+
58+
// Remove that comment
59+
const updatedComments = [
60+
...comments.slice(0, commentIndex),
61+
...comments.slice(commentIndex + 1)
62+
];
63+
64+
console.table(updatedComments);
3865

3966
</script>
4067
</body>

0 commit comments

Comments
 (0)