Skip to content

Commit 97d6ae5

Browse files
committed
added solution for wesbos#7
1 parent 848e56b commit 97d6ae5

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

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

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,69 @@
3232
// }
3333
// });
3434

35-
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
35+
const isAdult = people.some(function(person) {
36+
const currentYear = (new Date()).getFullYear();
37+
if(currentYear - person.year >=19){
38+
return true;
39+
}
40+
});
41+
42+
//const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
3643

3744
console.log({isAdult});
3845
// Array.prototype.every() // is everyone 19?
3946

40-
const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
41-
console.log({allAdults});
47+
// const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
48+
// console.log({allAdults});
49+
50+
const allAdults = people.every(function(person) {
51+
const currentYear = (new Date()).getFullYear();
52+
if(currentYear - person.year >=19){
53+
return true;
54+
}
55+
});
56+
57+
console.log({allAdults});
4258

4359
// Array.prototype.find()
4460
// Find is like filter, but instead returns just the one you are looking for
4561
// find the comment with the ID of 823423
4662

47-
48-
const comment = comments.find(comment => comment.id === 823423);
63+
const comment = comments.find(function(comment){
64+
return comment.id === 823423;
65+
});
4966

5067
console.log(comment);
5168

69+
70+
71+
72+
// const comment = comments.find(comment => comment.id === 823423);
73+
74+
// console.log(comment);
75+
5276
// Array.prototype.findIndex()
5377
// Find the comment with this ID
5478
// delete the comment with the ID of 823423
55-
const index = comments.findIndex(comment => comment.id === 823423);
56-
console.log(index);
79+
// const index = comments.findIndex(comment => comment.id === 823423);
80+
// console.log(index);
5781

5882
// comments.splice(index, 1);
5983

60-
const newComments = [
61-
...comments.slice(0, index),
62-
...comments.slice(index + 1)
63-
];
84+
// const newComments = [
85+
// ...comments.slice(0, index),
86+
// ...comments.slice(index + 1)
87+
// ];
88+
89+
const index = comments.findIndex(function(comment) {
90+
return comment.id === 823423;
91+
});
92+
93+
console.log(index);
94+
95+
const newComments = comments.splice(index,1);
96+
97+
console.table(newComments);
6498

6599
</script>
66100
</body>

0 commit comments

Comments
 (0)