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

Skip to content

Commit 89c8427

Browse files
lección wesbos#7
1 parent 80ef3e8 commit 89c8427

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

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

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

3148
// Array.prototype.find()
3249
// Find is like filter, but instead returns just the one you are looking for
3350
// find the comment with the ID of 823423
51+
console.log('Find the comment with the ID 823423');
52+
const find = comments.find(function(people){
53+
if(people.id == 823423){
54+
return true;
55+
}
56+
});
57+
console.log(find);
3458

3559
// Array.prototype.findIndex()
3660
// Find the comment with this ID
3761
// delete the comment with the ID of 823423
62+
console.log('Find the comment with this ID');
63+
console.log('Delete the comment with the ID of 823423');
64+
const findIndex = comments.findIndex(function(people){
65+
if(people.id == 823423){
66+
return true;
67+
}
68+
});
69+
console.log(findIndex);
70+
const newComments = [
71+
...comments.slice(0, findIndex),
72+
...comments.slice(findIndex + 1)
73+
];
74+
75+
3876

3977
</script>
4078
</body>

0 commit comments

Comments
 (0)