Visitar URL original
Complete · wesbos/JavaScript30@913ec12 · GitHub
Skip to content

Commit 913ec12

Browse files
committed
Complete
1 parent c4ce5fe commit 913ec12

2 files changed

Lines changed: 37 additions & 68 deletions

File tree

‎07 - Array Cardio Day 2/index-FINISHED.html‎

Lines changed: 0 additions & 68 deletions
This file was deleted.

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

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

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19 or older?
29+
30+
// Old Way
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+
38+
// ES6 Way
39+
const isAdult = people.some(person => {
40+
const currentYear = (new Date()).getFullYear();
41+
return currentYear - person.year >= 19;
42+
})
43+
console.log(isAdult);
44+
2945
// Array.prototype.every() // is everyone 19 or older?
3046

47+
const isEveryoneAdult = people.every(function (person) {
48+
const currentYear = (new Date()).getFullYear();
49+
if (currentYear - person.year >= 19) {
50+
return true;
51+
}
52+
});
53+
console.log(isEveryoneAdult);
54+
3155
// Array.prototype.find()
3256
// Find is like filter, but instead returns just the one you are looking for
3357
// find the comment with the ID of 823423
3458

59+
const findComment = comments.find(comment => comment.id === 823423);
60+
61+
console.log(findComment);
62+
3563
// Array.prototype.findIndex()
3664
// Find the comment with this ID
3765
// delete the comment with the ID of 823423
3866

67+
const findIndex = comments.findIndex(comment => comment.id === 823423);
68+
69+
console.log(findIndex);
70+
71+
// Deletes the comment with corresponding ID.
72+
comments.splice(findIndex, 1);
73+
74+
console.log(comments);
75+
3976
</script>
4077
</body>
4178
</html>

0 commit comments

Comments
 (0)