Skip to content

Commit 5df5ec9

Browse files
committed
add Day 7
1 parent 84421e1 commit 5df5ec9

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ <h5 class="font-weight-bold font-italic text-white team-tag">TEAM</h5>
226226
Day#21|<span>JavaScript Drum Kit</span>
227227
</li>
228228
</a>
229-
<a class="project-item" href="#.html">
229+
<a class="project-item" href="#">
230230
<li>Day#22|<span>JS and CSS Clock</span>
231231
</li>
232232
</a>
@@ -782,7 +782,7 @@ <h5 class="font-weight-bold font-italic text-white team-tag">TEAM</h5>
782782
<li>Day#06|<span>Type Ahead</span>
783783
</li>
784784
</a>
785-
<a class="project-item" href="#">
785+
<a class="project-item" href="team/Debby/Day-7-Array_Day_2/index.html">
786786
<li>Day#07|<span>Array Cardio Day 2</span>
787787
</li>
788788
</a>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
21+
// 抓到今年
22+
const currentYear = (new Date()).getFullYear();
23+
24+
// 回傳每一個人的年紀
25+
const personYear = people.map(person => currentYear - person.year);
26+
console.table(personYear);
27+
28+
const isAdult = people.some(person => (currentYear - person.year >= 19));
29+
console.log(isAdult);
30+
31+
32+
// Array.prototype.every() // is everyone 19 or older?
33+
34+
const isAllAdult = people.every(person => (currentYear - person.year >= 19))
35+
console.log(isAllAdult);
36+
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+
42+
const findComment = comments.find(comment => (comment.id === 823423)).text
43+
console.log(findComment);
44+
45+
// Array.prototype.findIndex()
46+
// Find the comment with this ID
47+
// delete the comment with the ID of 123523
48+
49+
// 找到 123523 的 Index
50+
const findIndexComment = comments.findIndex(comment => (comment.id === 123523))
51+
console.log(findIndexComment);
52+
53+
// 刪除原陣列資料 splice
54+
// comments.splice(findIndexComment,1);
55+
// console.table(comments);
56+
57+
// 刪掉資料並產生新的陣列
58+
const newComments = [
59+
...comments.slice(0,findIndexComment), // 複製起始 index(0) 到 findIndexComment (不包含自己)
60+
...comments.slice(findIndexComment+1) // 複製 findIndexComment+1 到之後的資料
61+
]
62+
console.table(newComments);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Array Cardio Day-2 💪💪</title>
6+
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400&display=swap" rel="stylesheet">
7+
<style type="text/css">
8+
body {
9+
font-family: 'Heebo', sans-serif;
10+
background-color: #FDFEFE;
11+
color: #2C3E50;
12+
padding: 30px;
13+
}
14+
a {
15+
/*border: 1px solid;*/
16+
padding: 3px 10px;
17+
border-radius: 5px;
18+
background-color: #EAF2F8;
19+
color: #5DADE2;
20+
text-decoration: none;
21+
transition: 0.2s;
22+
margin-left: 10px;
23+
}
24+
a:hover {
25+
background-color: #D4E6F1;
26+
}
27+
a:active {
28+
box-shadow: 0px 0px 0px 1px #5dade2, 0px 0px 0px 3px #5dade273;
29+
}
30+
</style>
31+
</head>
32+
<body>
33+
<p style="margin-bottom: 30px;"><em>Psst: have a look at the JavaScript Console</em> 💁</p>
34+
<p>📒 Note 👉 <a href="https://paper.dropbox.com/doc/JS-30-Day-7-Array-Cardio-Day-2--AzqwLru4f_ZKyfFYDkCfrWv~Ag-y2V7VmeX1EmL1dnZbAuAD" target="_blank">click me</a></p>
35+
36+
<p style="margin-top: 20px;">📌 Want to 👉<a href="https://lizwang50.github.io/JavaScript-30weeks/">Back home</a></p>
37+
<script type="text/javascript" src="all.js"></script>
38+
</body>
39+
</html>

0 commit comments

Comments
 (0)