Skip to content

Commit e2c77da

Browse files
author
Kyle Bradshaw
committed
07 array cardio 2 final kb
1 parent 5b82b6d commit e2c77da

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,50 @@
2424
{ text: 'Nice Nice Nice!', id: 542328 }
2525
];
2626

27+
function n19(person) {
28+
const currYr = (new Date().getFullYear());
29+
return (currYr - person.year) >= 19 ? true : false;
30+
}
31+
2732
// Some and Every Checks
2833
// Array.prototype.some() // is at least one person 19?
34+
const isAdult = people.some(function(person){
35+
return n19(person);
36+
});
37+
console.log(isAdult, 'are some at least 19?');
38+
2939
// Array.prototype.every() // is everyone 19?
40+
const all = people.every(function(person){
41+
return n19(person);
42+
});
43+
console.log(all, 'is everyone at least 19?');
3044

3145
// Array.prototype.find()
3246
// Find is like filter, but instead returns just the one you are looking for
3347
// find the comment with the ID of 823423
48+
const found = comments.find( comment => comment.id === 823423);
49+
console.log(found, 'comment w/ id: 823423')
50+
3451

52+
function outputComments(comments) {
53+
const c = []
54+
comments.forEach(comment => c.push(comment.text));
55+
return c;
56+
}
3557
// Array.prototype.findIndex()
3658
// Find the comment with this ID
3759
// delete the comment with the ID of 823423
60+
const foundIdx = comments.findIndex( comment => comment.id === 823423);
61+
console.log(comments.length, outputComments(comments));
62+
comments.splice(foundIdx, 1);
63+
console.log(comments.length, outputComments(comments));
64+
65+
66+
const newComments = [
67+
...comments.slice(0, foundIdx),
68+
...comments.slice(foundIdx + 1)
69+
];
70+
console.log(newComments,'spreaded');
3871

3972
</script>
4073
</body>

0 commit comments

Comments
 (0)