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

Skip to content

Commit ddcb8a2

Browse files
committed
adding script wesbos#7
1 parent 4b88f1d commit ddcb8a2

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,56 @@
2626

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
29-
// Array.prototype.every() // is everyone 19 or older?
29+
const isAdultV1 = people.some(function(person){
30+
const currentYear = (new Date()).getFullYear();
31+
if (currentYear - person.year >= 19) {
32+
return true;
33+
}
34+
});
35+
console.log({isAdultV1});
36+
37+
const isAdultV2 = people.some(person => {
38+
const currentYear = (new Date()).getFullYear();
39+
return currentYear - person.year >= 19;
40+
});
41+
console.log({isAdultV2});
3042

43+
const isAdultV3 = people.some(person =>
44+
((new Date()).getFullYear()) - person.year >= 19
45+
);
46+
console.log({isAdultV3});
47+
48+
// Array.prototype.every() // is everyone 19 or older?
49+
const allAdults = people.every(person =>
50+
((new Date()).getFullYear()) - person.year >= 19
51+
);
52+
console.log({allAdults});
3153
// Array.prototype.find()
3254
// Find is like filter, but instead returns just the one you are looking for
3355
// find the comment with the ID of 823423
56+
const commentV1 = comments.find(function(comment) {
57+
if (comment.id === 823423) {
58+
return true;
59+
}
60+
});
61+
console.log(commentV1);
62+
63+
const commentV2 = comments.find(comment => comment.id === 823423);
64+
console.log(commentV2);
3465

3566
// Array.prototype.findIndex()
3667
// Find the comment with this ID
3768
// delete the comment with the ID of 823423
69+
const index = comments.findIndex(comment => comment.id === 823423);
70+
console.log(index);
71+
// updates the exisitng array
72+
comments.splice(index,1);
73+
74+
// creates a new array so that the old one can still be referenced
75+
const newComments = [
76+
...comments.slice(0,index),
77+
...comments.slice(index + 1)
78+
];
3879

3980
</script>
4081
</body>

0 commit comments

Comments
 (0)