Skip to content

Commit 377471c

Browse files
Eric LeeEric Lee
authored andcommitted
Finished project
1 parent d2198d3 commit 377471c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,41 @@
3030
// if(currentYear - person.year >= 19) {
3131
// return true;
3232
// }
33-
// });
33+
// })
34+
35+
const isAdult = people.some(person => {
36+
const currentYear = (new Date()).getFullYear();
37+
return (currentYear - person.year) >= 19;
38+
});
3439

35-
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
36-
37-
console.log({isAdult});
3840
// Array.prototype.every() // is everyone 19?
41+
const allAdults = people.every(person => {
42+
const currentYear = (new Date()).getFullYear();
43+
return (currentYear - person.year) >= 19;
44+
});
3945

40-
const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
41-
console.log({allAdults});
4246

4347
// Array.prototype.find()
4448
// Find is like filter, but instead returns just the one you are looking for
4549
// find the comment with the ID of 823423
50+
const foundComment = comments.find(text => return text.id == 823423);
4651

4752

48-
const comment = comments.find(comment => comment.id === 823423);
49-
50-
console.log(comment);
51-
5253
// Array.prototype.findIndex()
5354
// Find the comment with this ID
5455
// delete the comment with the ID of 823423
55-
const index = comments.findIndex(comment => comment.id === 823423);
56-
console.log(index);
56+
const foundIndex = comments.findIndex(text => return text.id == 823423);
5757

58-
// comments.splice(index, 1);
58+
comments.splice(foundIndex);
59+
60+
// or
5961

6062
const newComments = [
61-
...comments.slice(0, index),
62-
...comments.slice(index + 1)
63+
...comments.splice(0, foundIndex),
64+
...comments.splice(foundIndex+1)
6365
];
6466

67+
6568
</script>
6669
</body>
6770
</html>

0 commit comments

Comments
 (0)