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 f4232a6

Browse files
committed
fix soyaine#65 修复一些问题
3 的排序没有使用字段 4 排序用错了变量名 7 里面也用错了字段名,应该取逗号后的单词
1 parent 0a6c3e4 commit f4232a6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

‎04 - Array Cardio Day 1/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 04 Array Cardio 💪 指南一
22

3-
> 作者:©[未枝丫](https://github.com/soyaine)
3+
> 作者:©[Soyaine](https://github.com/soyaine)
44
> 简介:[JavaScript30](https://javascript30.com)[Wes Bos](https://github.com/wesbos) 推出的一个 30 天挑战。项目免费提供了 30 个视频教程、30 个挑战的起始文档和 30 个挑战解决方案源代码。目的是帮助人们用纯 JavaScript 来写东西,不借助框架和库,也不使用编译器和引用。现在你看到的是这系列指南的第 4 篇。完整指南在 [GitHub](https://github.com/soyaine/JavaScript30),喜欢请 Star 哦♪(^∇^*)
55
66
## 实现效果
@@ -27,7 +27,7 @@ console.table(thing)
2727
4. 计算所有的发明家加起来一共活了多少岁
2828
5. 按照他们活了多久来进行排序
2929
6. 筛选出一个网页里含有某个词语的标题
30-
7. 按照姓氏来对发明家进行排序
30+
7. 按照姓氏来进行排序
3131
8. 统计给出数组中各个物品的数量
3232

3333
## 相关知识

‎04 - Array Cardio Day 1/index-SOYAINE.html‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@
4444

4545
// Array.prototype.filter()
4646
// 1. Filter the list of inventors for those who were born in the 1500's
47-
// 筛选 16 世纪出生的人
47+
// 1. 筛选 16 世纪出生的人
4848
const fifteen = inventors.filter(function (inventor) {
4949
if (inventor.year >= 1500 && inventor.year < 1600) {
5050
return true;
5151
}
5252
});
53+
console.log('1. 筛选 16 世纪出生的人');
5354
console.table(fifteen);
5455

5556
const __fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600));
@@ -59,6 +60,7 @@
5960
// Array.prototype.map()
6061
// 2. Give us an array of the inventors' first and last names
6162
// 展示上面发明家的姓名
63+
console.log('2. 展示上面发明家的姓名');
6264
const fullNames = inventors.map(inventor => inventor.first + ' ' + inventor.last);
6365
// const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
6466
console.log(fullNames);
@@ -67,6 +69,7 @@
6769
// Array.prototype.sort()
6870
// 3. Sort the inventors by birthdate, oldest to youngest
6971
// 把这些人从大到小进行排序
72+
console.log('3. 把发明家从大到小进行排序');
7073
// const ordered = inventors.sort(function(firstName, secondName) {
7174
// if(firstName.year > secondName.year) {
7275
// return 1; // 对 sort 函数,返回值为 -1 排在前面,1 排在后面
@@ -76,13 +79,15 @@
7679
// });
7780
// console.table(ordered);
7881

79-
const __ordered = inventors.sort((a, b) => (a > b) ? 1 : -1);
82+
const __ordered = inventors.sort((a, b) => (a.year > b.year) ? 1 : -1);
8083
console.table(__ordered);
8184

8285

8386
// Array.prototype.reduce()
8487
// 4. How many years did all the inventors live
8588
// 他们所有人一共活了多少岁
89+
console.log('4. 所有发明家一共活了多少岁');
90+
8691
// 下面三种写法是一样的效果
8792
// var total = 0;
8893
// for(var i = 0; i < inventors.length; i++) {
@@ -102,7 +107,8 @@
102107

103108
// 5. Sort the inventors by years lived、
104109
// 按照他们在世的岁数进行排序
105-
const oldest = people.sort((a, b) => {
110+
console.log('5. 按照发明家在世的岁数进行排序');
111+
const oldest = inventors.sort((a, b) => {
106112
const last = a.passed - a.year;
107113
const next = b.passed - b.year;
108114
return (next < last) ? -1 : 1;
@@ -131,16 +137,18 @@
131137

132138
// 7. sort Exercise
133139
// Sort the people alphabetically by last name
134-
// 按照姓氏的字母进行排序
140+
// 按照姓氏(逗号后面的单词)的字母进行排序
141+
console.log('7. 按照people姓氏(逗号后面的单词)的字母进行排序');
135142
const sortName = people.sort((a, b) => {
136-
return (a.last> b.last) ? 1 : -1;
143+
return (a.split(', ')[1]> b.split(', ')[1]) ? 1 : -1;
137144
})
138145
console.table(sortName);
139146

140147

141148
// 8. Reduce Exercise
142149
// Sum up the instances of each of these
143150
// 统计各个物品的数量
151+
console.log('8. 统计各个物品的数量');
144152
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car',
145153
'truck'
146154
];

0 commit comments

Comments
(0)

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