Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2d8138

Browse files
Day 07 files
1 parent b4fd32b commit f2d8138

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Array Cardio Day 2 🤝💪💪</title>
8+
</head>
9+
<body>
10+
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
11+
<script src="index.js"></script>
12+
</body>
13+
</html>

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ## Array Cardio Day 2
2+
3+
const people = [
4+
{ name: "Wes", year: 1988 },
5+
{ name: "Kait", year: 1986 },
6+
{ name: "Irv", year: 1970 },
7+
{ name: "Lux", year: 2015 },
8+
];
9+
10+
const comments = [
11+
{ text: "Love this!", id: 523423 },
12+
{ text: "Super good", id: 823423 },
13+
{ text: "You are the best", id: 2039842 },
14+
{ text: "Ramen is my fav food ever", id: 123523 },
15+
{ text: "Nice Nice Nice!", id: 542328 },
16+
];
17+
18+
// Some and Every Checks
19+
// Array.prototype.some() // is at least one person 19 or older?
20+
const isAdult = people.some((person) => {
21+
const currentYear = new Date().getFullYear();
22+
return currentYear - person.year >= 19;
23+
});
24+
25+
console.log(isAdult);
26+
27+
// Array.prototype.every() // is everyone 19 or older?
28+
const allAdults = people.every((person) => {
29+
const currentYear = new Date().getFullYear();
30+
return currentYear - person.year >= 19;
31+
});
32+
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+
const findComment = comments.find((comment) => {
39+
return comment.id === 823423 ? comment.text : false;
40+
});
41+
42+
console.log(findComment);
43+
44+
// Array.prototype.findIndex()
45+
// Find the comment with this ID
46+
// delete the comment with the ID of 823423
47+
const index = comments.findIndex((comment) => comment.id === 823423);
48+
console.log(index);
49+
// comments.splice(index,1);
50+
51+
const newComments = [...comments.slice(0, index), ...comments.slice(index + 1)];
52+
console.table(newComments);
53+
console.table(comments);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /