Skip to content

Commit 2b4b9ab

Browse files
committed
seven done
1 parent 884582c commit 2b4b9ab

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

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

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,69 @@
2626

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19?
29-
// Array.prototype.every() // is everyone 19?
29+
//will return true if there is at least one adult in people array who is over 19
30+
31+
// const isAdult = people.some(function(person){
32+
// const currentYear = (new Date()).getFullYear();
33+
// if(currentYear - person.year >= 19){
34+
// return true;
35+
// }
36+
// });
37+
// console.log(isAdult);
38+
//or
39+
40+
41+
const isAdult = people.some(person => {
42+
const currentYear = (new Date()).getFullYear();
43+
return currentYear - person.year >= 19;
44+
});
45+
console.log(isAdult);
46+
47+
// Array.prototype.every() // is everyone 19?
48+
const allAdult = people.every(person => {
49+
const currentYear = (new Date()).getFullYear();
50+
return currentYear - person.year >= 19;
51+
});
52+
console.log(allAdult);
53+
54+
55+
56+
// // Array.prototype.find()
57+
// const theComment = comments.find(function(comment) {
58+
// if(comment.id === 823423){
59+
// return true;
60+
// }
61+
// });
62+
// console.log(theComment);
63+
//or
64+
65+
const theComment = comments.find(comment =>
66+
comment.id === 823423);
67+
console.log(theComment);
68+
3069

31-
// Array.prototype.find()
3270
// Find is like filter, but instead returns just the one you are looking for
3371
// find the comment with the ID of 823423
3472

3573
// Array.prototype.findIndex()
3674
// Find the comment with this ID
3775
// delete the comment with the ID of 823423
3876

77+
const index = comments.findIndex(comment =>
78+
comment.id === 823423);
79+
console.log('index', index);
80+
81+
// comments.splice(index, 1);
82+
83+
//popular in redux world:
84+
const newComments = [
85+
...comments.slice(0, index),
86+
...comments.slice(index + 1)
87+
];
88+
89+
//will build new array of comments
90+
//... will spread items into new array
91+
3992
</script>
4093
</body>
4194
</html>

0 commit comments

Comments
 (0)