Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de69ad0

Browse files
committed
challenge 7 is completed. Array methods.
1 parent 13d32fb commit de69ad0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,41 @@
2525

2626
// Some and Every Checks
2727
// 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);
36+
console.log({isAdult});
37+
2838
// Array.prototype.every() // is everyone 19?
39+
const allAdult = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
40+
console.log({allAdult});
2941

3042
// Array.prototype.find()
3143
// Find is like filter, but instead returns just the one you are looking for
3244
// find the comment with the ID of 823423
45+
const comment = comments.find(comment => comment.id === 823423);
46+
console.log(comment);
3347

3448
// Array.prototype.findIndex()
3549
// Find the comment with this ID
3650
// delete the comment with the ID of 823423
51+
const index = comments.findIndex(comment => comment.id === 823423);
52+
console.log(index);
53+
console.table(comments);
54+
55+
// comments.splice(index, 1);
56+
// console.table(comments);
57+
58+
const newComments = [
59+
...comments.slice(0, index),
60+
...comments.slice(index + 1)
61+
];
62+
console.table(newComments);
3763

3864
</script>
3965
</body>

0 commit comments

Comments
 (0)