Skip to content

Commit 4827056

Browse files
committed
Finsh challenge wesbos#6/7
1 parent 06cf60f commit 4827056

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

07 - Array Cardio Day 2/index.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Array Cardio 💪💪</title>
6+
</head>
7+
<body>
8+
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
9+
<script>
10+
// ## Array Cardio Day 2
11+
12+
const people = [
13+
{ name: 'Wes', year: 1988 },
14+
{ name: 'Kait', year: 1986 },
15+
{ name: 'Irv', year: 1970 },
16+
{ name: 'Lux', year: 2015 }
17+
];
18+
19+
const comments = [
20+
{ text: 'Love this!', id: 523423 },
21+
{ text: 'Super good', id: 823423 },
22+
{ text: 'You are the best', id: 2039842 },
23+
{ text: 'Ramen is my fav food ever', id: 123523 },
24+
{ text: 'Nice Nice Nice!', id: 542328 }
25+
];
26+
27+
// Some and Every Checks
28+
// Array.prototype.some() // is at least one person 19 or older?
29+
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
30+
31+
console.log(isAdult);
32+
33+
// Array.prototype.every() // is everyone 19 or older?
34+
const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
35+
36+
console.log(allAdults);
37+
38+
// Array.prototype.find()
39+
// Find is like filter, but instead returns just the one you are looking for
40+
// find the comment with the ID of 823423
41+
const comment = comments.find(comm => comm.id === 823423);
42+
43+
console.log(comment);
44+
45+
// Array.prototype.findIndex()
46+
// Find the comment with this ID
47+
// delete the comment with the ID of 823423
48+
const index = comments.findIndex(comm => comm.id === 823423);
49+
50+
console.log(index);
51+
52+
/* console.log(comments);*/
53+
/* comments.splice(index, 1);*/
54+
/* console.log(comments);*/
55+
56+
const newComments = [
57+
...comments.slice(0, index),
58+
...comments.slice(index + 1)
59+
];
60+
console.log(newComments);
61+
62+
</script>
63+
</body>
64+
</html>

0 commit comments

Comments
 (0)