Skip to content

Commit 25dcae9

Browse files
committed
Finished wesbos#7
1 parent 703ada0 commit 25dcae9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

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

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
29+
30+
// const isAdult = people.some(function(person) {
31+
// const currentYear = (new Date()).getFullYear();
32+
// if (currentYear - person.year >= 19) {
33+
// return true;
34+
// }
35+
// });
36+
37+
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
38+
console.log({isAdult});
39+
2940
// Array.prototype.every() // is everyone 19 or older?
41+
const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
42+
console.log({allAdults});
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
3447

48+
// const comment = comments.find(function(comment) {
49+
// if (comment.id === 823423 ) {
50+
// return true;
51+
// }
52+
// });
53+
54+
// const comment = comments.find(comment => (comment.id === 823423) ? true : false);
55+
const comment = comments.find(comment => (comment.id === 823423));
56+
57+
console.log(comment);
58+
3559
// Array.prototype.findIndex()
3660
// Find the comment with this ID
3761
// delete the comment with the ID of 823423
62+
const index = comments.findIndex(comment => (comment.id === 823423));
63+
// console.log(index);
64+
65+
// comments.splice(index, 1);
66+
// console.log(comments);
67+
// console.table(comments);
68+
69+
const newComments = [
70+
...comments.slice(0, index),
71+
...comments.slice(index + 1)
72+
];
73+
console.table(newComments);
3874

3975
</script>
4076
</body>

0 commit comments

Comments
 (0)