Skip to content

Commit 91ec4f1

Browse files
committed
Completed Day wesbos#7
1 parent d965a21 commit 91ec4f1

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 isSomeAdult = people.some(person => ((new Date).getFullYear() - person.year) >= 19);
30+
console.log({isSomeAdult});
31+
32+
// Array.prototype.every() // is everyone 19 or older?
33+
const isEveryAdult = people.every(person => ((new Date).getFullYear() - person.year) >= 19);
34+
console.log({isEveryAdult});
35+
36+
// Array.prototype.find()
37+
// Find is like filter, but instead returns just the one you are looking for
38+
// find the comment with the ID of 823423
39+
const comment = comments.find(comment => comment.id === 823423);
40+
console.log({comment});
41+
42+
// Array.prototype.findIndex()
43+
// Find the comment with this ID
44+
// delete the comment with the ID of 823423
45+
const index = comments.findIndex(comment => comment.id === 823423);
46+
const newComments = [...comments.slice(0, index), ...comments.slice(index + 1)];
47+
console.table(newComments);
48+
49+
</script>
50+
</body>
51+
</html>

0 commit comments

Comments
 (0)