Skip to content

Commit e565b41

Browse files
committed
Array cardio day 2.
Worked through code challenge provided.
1 parent 60ad1dc commit e565b41

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

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

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
29+
// const isAdult = people.some(function(person){
30+
// const currentYear = (new Date()).getFullYear();
31+
// if(currentYear - person.year >= 19) {
32+
// return true;
33+
// }
34+
// });
35+
// console.log({isAdult}); same as below
36+
37+
// const isAdult = people.some(person => {
38+
// const currentYear = (new Date()).getFullYear();
39+
// return currentYear - person.year >= 19;
40+
// });
41+
// console.log({isAdult}); same as below
42+
43+
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
44+
45+
console.log({isAdult});
46+
2947
// Array.prototype.every() // is everyone 19 or older?
48+
const allAdult = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
49+
50+
console.log({allAdult});
3051

3152
// Array.prototype.find()
3253
// Find is like filter, but instead returns just the one you are looking for
3354
// find the comment with the ID of 823423
55+
// const comment = comments.find(function(comment){
56+
// if(comment.id === 823423) {
57+
// return true;
58+
// }
59+
// }); same as below one line of code
60+
const comment = comments.find(comment => comment.id === 823423);
61+
console.log(comment);
3462

3563
// Array.prototype.findIndex()
3664
// Find the comment with this ID
3765
// delete the comment with the ID of 823423
66+
const index = comments.findIndex(comment => comment.id === 823423);
67+
console.log(index);
68+
comments.splice(index, 1); //same as below
69+
// const newComments = [
70+
// ...comment.slice(0, index),
71+
// ...comment.slice(index + 1) //... uses spread operator
72+
// ]
3873

3974
</script>
4075
</body>

0 commit comments

Comments
 (0)