Visitar URL original
Merge pull request #7 from cydseelen/array-cardio · wesbos/JavaScript30@4148545 · GitHub
Skip to content

Commit 4148545

Browse files
authored
Merge pull request #7 from cydseelen/array-cardio
challenge complete.
2 parents 1375cc8 + ae75cff commit 4148545

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,37 @@
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+
36+
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19 );
37+
38+
console.log({isAdult});
2939
// Array.prototype.every() // is everyone 19 or older?
40+
const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19 );
41+
42+
console.log(allAdults);
3043

3144
// Array.prototype.find()
3245
// Find is like filter, but instead returns just the one you are looking for
3346
// find the comment with the ID of 823423
34-
47+
const comment = comments.find(function(comment) {
48+
if(comment.id === 823423) {
49+
return true;
50+
}
51+
});
52+
console.log(comment);
3553
// Array.prototype.findIndex()
3654
// Find the comment with this ID
3755
// delete the comment with the ID of 823423
56+
const index = comments.findIndex(comment => comment.id === 823423);
57+
console.log(index);
3858

59+
comments.splice(index, 1);
3960
</script>
4061
</body>
4162
</html>

0 commit comments

Comments
 (0)