Visitar URL original
Finish Day 7 · wesbos/JavaScript30@9a0dce1 · GitHub
Skip to content

Commit 9a0dce1

Browse files
committed
Finish Day 7
1 parent ccee8e8 commit 9a0dce1

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

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

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

0 commit comments

Comments
 (0)