Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98c5bfe

Browse files
committed
Added Array Cardio Day 2 (wesbos#7)
1 parent fe63da9 commit 98c5bfe

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,45 @@
2525
];
2626

2727
// Some and Every Checks
28+
const currentYear = (new Date()).getFullYear();
29+
const ageLimit = 19;
30+
2831
// Array.prototype.some() // is at least one person 19 or older?
29-
// Array.prototype.every() // is everyone 19 or older?
32+
const isSome = people.some(p => currentYear - p.year >= ageLimit);
33+
console.log("It's " + isSome + " that some people are " + ageLimit + " or older.");
34+
35+
// Array.prototype.every() // is everyone 19 or older?
36+
const isEvery = people.every(p => currentYear - p.year >= ageLimit);
37+
console.log("It's " + isEvery + " that everyone is " + ageLimit + " or older.");
3038

3139
// Array.prototype.find()
40+
const commentId = 823423;
41+
3242
// Find is like filter, but instead returns just the one you are looking for
3343
// find the comment with the ID of 823423
44+
const comment = comments.find(c => c.id === commentId)
45+
46+
if (comment !== undefined){
47+
console.log(comment);
48+
} else {
49+
console.warn("Couldn't find comment " + commentId);
50+
}
3451

3552
// Array.prototype.findIndex()
3653
// Find the comment with this ID
37-
// delete the comment with the ID of 823423
54+
const commentIndex = comments.findIndex(c => c.id === commentId);
55+
// delete the comment with the ID of 823423
56+
57+
// Keep the original array
58+
const newComments = [
59+
...comments.slice(0, commentIndex),
60+
...comments.slice(commentIndex + 1)
61+
];
62+
console.table(newComments);
3863

64+
// OR modify it
65+
comments.splice(commentIndex, 1);
66+
console.table(comments);
3967
</script>
4068
</body>
4169
</html>

0 commit comments

Comments
 (0)