Skip to content

Commit 5ee2329

Browse files
author
Justin Ramel
committed
Merge branch 'master' of github.com:justinramel/JavaScript30
2 parents 4fd3c67 + 1234cd6 commit 5ee2329

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,36 @@
2323
{ text: 'Nice Nice Nice!', id: 542328 }
2424
];
2525

26+
const year = (new Date()).getFullYear()
27+
const age = (personYear) => year - personYear
28+
const nineteen = (person) => person.year >= 19
29+
2630
// Some and Every Checks
2731
// Array.prototype.some() // is at least one person 19?
28-
// const isAdult = people.some(function(person) {
29-
// const currentYear = (new Date()).getFullYear();
30-
// if(currentYear - person.year >= 19) {
31-
// return true;
32-
// }
33-
// });
34-
35-
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
32+
const isAdult = people.some(nineteen)
33+
console.log({isAdult})
3634

37-
console.log({isAdult});
3835
// Array.prototype.every() // is everyone 19?
39-
40-
const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
41-
console.log({allAdults});
36+
const allAdults = people.every(nineteen)
37+
console.log({allAdults})
4238

4339
// Array.prototype.find()
4440
// Find is like filter, but instead returns just the one you are looking for
4541
// find the comment with the ID of 823423
46-
47-
48-
const comment = comments.find(comment => comment.id === 823423);
49-
42+
const comment = comments.find(comment => comment.id === 823423)
5043
console.log(comment);
5144

5245
// Array.prototype.findIndex()
5346
// Find the comment with this ID
5447
// delete the comment with the ID of 823423
55-
const index = comments.findIndex(comment => comment.id === 823423);
48+
const index = comments.findIndex(comment => comment.id === 823423)
5649
console.log(index);
5750

58-
// comments.splice(index, 1);
59-
6051
const newComments = [
6152
...comments.slice(0, index),
6253
...comments.slice(index + 1)
63-
];
54+
]
55+
console.table(newComments)
6456

6557
</script>
6658
</body>

0 commit comments

Comments
 (0)