Skip to content

Commit cb300d9

Browse files
committed
Finished wesbos#7
1 parent db24ec2 commit cb300d9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,46 @@
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) { // this is function declaration
30+
// const currentYear = (new Date()).getFullYear()
31+
// if (person.year - person.year >= 19) {
32+
// return true
33+
// }
34+
// })
35+
const isAdult = people.some(person => { // This is the ES6 way (arrow function)
36+
const currentYear = (new Date()).getFullYear()
37+
return currentYear - person.year >= 19
38+
})
39+
console.log({isAdult})
40+
2941
// Array.prototype.every() // is everyone 19 or older?
42+
const allAdult = people.every(person => { // This is the ES6 way (arrow function)
43+
const currentYear = (new Date()).getFullYear()
44+
return currentYear - person.year >= 19
45+
})
46+
console.log({ allAdult })
47+
3048

3149
// Array.prototype.find()
3250
// Find is like filter, but instead returns just the one you are looking for
3351
// find the comment with the ID of 823423
52+
const comment = comments.find(comment => comment.id === 823423)
53+
console.log(comment)
3454

3555
// Array.prototype.findIndex()
3656
// Find the comment with this ID
3757
// delete the comment with the ID of 823423
58+
const index = comments.findIndex(comment => comment.id === 823423)
59+
60+
// comments.splice(index, 1)
3861

62+
// This way we are creating a new array from the comments array and excluding index from that new array
63+
const newComments = [
64+
...comments.slice(0, index),
65+
...comments.slice(index + 1)
66+
]
67+
console.table(newComments)
68+
3969
</script>
4070
</body>
4171
</html>

0 commit comments

Comments
 (0)