Skip to content

Commit 23c7e7d

Browse files
author
Carlos Filoteo
committed
Add solution for project 07.
1 parent 2b21f66 commit 23c7e7d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,31 @@
2626

2727
// Some and Every Checks
2828
// Array.prototype.some() // is at least one person 19?
29+
const isAdult = people.some(person => {
30+
const currYear = (new Date()).getFullYear()
31+
return (currYear - person.year) >= 19
32+
})
33+
34+
// One liner
35+
const isAdult2 = people.some(({year}) => ((new Date()).getFullYear() - year) >= 19)
36+
2937
// Array.prototype.every() // is everyone 19?
38+
const everyAdult = people.every(({year}) => ((new Date()).getFullYear() - year) >= 19)
3039

3140
// Array.prototype.find()
3241
// Find is like filter, but instead returns just the one you are looking for
3342
// find the comment with the ID of 823423
34-
43+
const cID = 823423
44+
const comment = comments.find(({id}) => id === cID)
45+
3546
// Array.prototype.findIndex()
3647
// Find the comment with this ID
3748
// delete the comment with the ID of 823423
49+
const index = comments.findIndex(({id}) => id === cID)
50+
const newComments = [
51+
...comments.splice(0, index),
52+
...comments.splice(index + 1)
53+
]
3854

3955
</script>
4056
</body>

0 commit comments

Comments
 (0)