Skip to content

Commit 0ca3e68

Browse files
committed
Finished day 7, array cardio wesbos#2
1 parent 2c58d7e commit 0ca3e68

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

07 - Array Cardio Day 2/index-START.html renamed to 07 - Array Cardio Day 2-finished/index-START.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,54 @@
2626

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
29+
30+
const isAdult = people.some(person => {
31+
const currentYear = (new Date()).getFullyear();
32+
return currentYear - person.year >= 19;
33+
});
34+
35+
console.log({isAdult});
36+
2937
// Array.prototype.every() // is everyone 19 or older?
3038

39+
const allAdult = people.every(person => {
40+
const currentYear = (new Date()).getFullyear();
41+
return currentYear - person.year >= 19;
42+
});
43+
44+
console.log({allAdult});
45+
3146
// Array.prototype.find()
3247
// Find is like filter, but instead returns just the one you are looking for
3348
// find the comment with the ID of 823423
3449

50+
const comment = comments.find(function(comment) {
51+
if (comment.id === 823423) {
52+
return true;
53+
}
54+
});
55+
56+
console.log(comment);
57+
58+
const comment = comments.find(comment =>
59+
comment.id === 823423);
60+
3561
// Array.prototype.findIndex()
3662
// Find the comment with this ID
3763
// delete the comment with the ID of 823423
3864

65+
const index = comments.findIndex(comment => comment.id === 823423);
66+
console.log(index);
67+
68+
comments.splice(index, 1);
69+
70+
// OR
71+
72+
const newComments = [
73+
...comments.slice(0, index),
74+
...comments.slice(index + 1)
75+
];
76+
3977
</script>
4078
</body>
4179
</html>

0 commit comments

Comments
 (0)