fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@@ -0,0 +1,69 @@
---
title: Iterate Through the Keys of an Object with a for...in Statement
localeTitle:  使用for ... in Statement中的对象键迭代
---
## 使用for ... in Statement中的对象键迭代
方法:
* 注意: `dot-notation`会导致此挑战出错。
* 必须使用`[square-bracket]`表示法来调用变量属性名称。
* 以下代码无效。
### 例1
```javascript
for (let user in obj) {
if(obj.user.online === true) {
//code
}
}
```
* 示例2演示了如何使用`[square-bracket]`表示法执行代码。
### 例2
```javascript
for (let user in obj) {
if(obj[user]online === true) {
//code
}
}
```
### 解:
```javascript
let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};
function countOnline(obj) {
// change code below this line
let result = 0;
for (let user in obj) {
if(obj[user].online === true) {
result++;
}
}
return result;
// change code above this line
}
console.log(countOnline(users));
```

View File

@@ -0,0 +1,14 @@
---
title: Access an Array's Contents Using Bracket Notation
localeTitle: 使用括号表示法访问数组的内容
---
## 使用括号表示法访问数组的内容
* 请记住数组索引从0开始因此b的位置将位于`myArray[1]`
## 解
```javascript
myArray[1] = "anything we want";
```

View File

@@ -0,0 +1,45 @@
---
title: Access Property Names with Bracket Notation
localeTitle: 使用括号表示法访问属性名称
---
## 使用括号表示法访问属性名称
方法:
* 使用括号表示法只需在`checkInventory()`函数中编写return语句。
* 以下代码块演示了所需的语法。
## 例:
```javascript
let juice = {
apple: 1.15,
orange: 1.45
};
function checkInventory(scannedItem) {
return juice[scannedItem];
}
```
## 解:
```javascript
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
// do not change code above this line
function checkInventory(scannedItem) {
// change code below this line
return foods[scannedItem];
}
// change code below this line to test different cases:
console.log(checkInventory("apples"));
```

View File

@@ -0,0 +1,23 @@
---
title: Add Items to an Array with push() and unshift()
localeTitle: 使用push和unshift将项添加到数组
---
## 使用push和unshift将项添加到数组
* 就像给出的示例一样,在数组上使用`.unshift()`方法将元素添加到数组的开头,并使用`.push()`方法将元素添加到数组的末尾。
## 解:
```javascript
function mixedNumbers(arr) {
// change code below this line
arr.unshift('I',2,'three');
arr.push(7,'VIII', 9);
// change code above this line
return arr;
}
// do not change code below this line
console.log(mixedNumbers(['IV', 5, 'six']));
```

View File

@@ -0,0 +1,35 @@
---
title: Add Items Using splice()
localeTitle: 使用splice添加项目
---
## 使用splice添加项目
* 使用接头函数必须删除从阵列的第一2个元件`arr` ,并用替换它们`DarkSalmon``BlanchedAlmond`
* 请记住,拼接功能最多可以使用三个参数。
## 例:
```javascript
arr.splice(0, 1, "Two");
/* The first two paramemters are the same as they were in the previous challenge.
`0` will start the `splice()` function off at index 0.
The second parameter `1` will remove only 1 variable from the array.
The final variable "Two" will replace the variable in arr[0].
Note: The final parameter can take more than 1 arguement.
*/
```
## 解:
```javascript
function htmlColorNames(arr) {
// change code below this line
arr.splice(0, 2, "DarkSalmon", "BlanchedAlmond");
// change code above this line
return arr;
}
// do not change code below this line
console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'PaleTurqoise', 'FireBrick']));
```

View File

@@ -0,0 +1,30 @@
---
title: Add Key-Value Pairs to JavaScript Objects
localeTitle: 将键值对添加到JavaScript对象
---
## 将键值对添加到JavaScript对象
* 食物对象已经宣布。剩下要做的就是添加三个新的`key-values`
```javascript
OBJECT[{KEY}] = {VALUE}
```
* 上面的代码将在对象中创建一个ney `key-value`
## 解
```javascript
let foods = {
apples: 25,
oranges: 32,
plums: 28
};
// change code below this line
foods['bananas'] = 13;
foods['grapes'] = 35;
foods['strawberries'] = 27;
// change code above this line
console.log(foods);
```

View File

@@ -0,0 +1,33 @@
---
title: Check For The Presence of an Element With indexOf()
localeTitle: 使用indexOf检查元素是否存在
---
## 使用indexOf检查元素是否存在
* 可以使用简单的`if-statement`来检查`indexOf()`函数返回的值是否小于0。
* 一旦发现了值,您就可以返回`true``false`
* `Solution-1`演示了一个简单的`if-statement`如何返回正确的结果。
## 方案1
```javascript
function quickCheck(arr, elem) {
if(arr.indexOf(elem)>=0) {
return true;
}
return false;
}
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
```
* `Solution-2`演示如何使用`? : (conditional)`解决问题`? : (conditional)`运算符。
## 方案2
```javascript
function quickCheck(arr, elem) {
return arr.indexOf(elem) >= 0 ? true : false;
}
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
```

View File

@@ -0,0 +1,55 @@
---
title: Check if an Object has a Property
localeTitle: 检查对象是否具有属性
---
## 检查对象是否具有属性
方法:
* 完成此挑战的最简单方法是创建一个“ `ìf-statement`来检查对象是否包含所有用户然后返回true或false语句。第一个解决方案就是这样做的。
* 第二个解决方案以完全相同的方式工作只有它在函数内使用1行代码 - `Conditional(ternary)-Operator` - `Conditional(ternary)-Operator`
[developer.mozilla.org](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)对三元运算符进行了更深入的分析。
### 方案1
```javascript
let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};
function isEveryoneHere(obj) {
// change code below this line
if(users.hasOwnProperty('Alan','Jeff','Sarah','Ryan')) {
return true;
}
return false;
// change code above this line
}
console.log(isEveryoneHere(users));
```
### 方案2
```javascript
function isEveryoneHere(obj) {
return (users.hasOwnProperty('Alan','Jeff','Sarah','Ryan')) ? true : false;
}
```

View File

@@ -0,0 +1,21 @@
---
title: Combine Arrays with the Spread Operator
localeTitle: 将数组与Spread运算符组合在一起
---
## 将数组与Spread运算符组合在一起
* 解决方案与给出的示例完全相同。只需将`fragment[]`数组插入到所需索引的`sentence[]`数组中。
## 解:
```javascript
function spreadOut() {
let fragment = ['to', 'code'];
let sentence = ["learning", ...fragment, "is", "fun"]; // change this line
return sentence;
}
// do not change code below this line
console.log(spreadOut());
```

View File

@@ -0,0 +1,20 @@
---
title: Copy an Array with the Spread Operator
localeTitle: 使用Spread Operator复制数组
---
## 使用Spread Operator复制数组
* 示例中的最后一个提示告诉您使用最近学习的方法。
* spread运算符将所有元素复制到一个新的空对象中。
\`\`\`的JavaScript whilenum> = 1{ newArr = \[... arr\] num--; }
```
- The code above will copy all of the elements into `newArr` but will also reinitialise `newArr` with every new iteration of the while loop.
- A new variable should first be initialised using the spread operator - `let obj = [...arr];` - then this variable should be added to the `newArr` for every iteration of the while loop.
## Solution:
```
JavaScript的 function copyMachinearrnum{ 让newArr = \[\]; whilenum> = 1{ //更改此行下方的代码 newArr.push\[... ARR\]; //更改此行以上的代码 num--; } 返回newArr; }
//在此处更改代码以测试不同的情况: console.logcopyMachine\[truefalsetrue\]2; \`\`\`

View File

@@ -0,0 +1,30 @@
---
title: Copy Array Items Using slice()
localeTitle: 使用slice复制数组项
---
## 使用slice复制数组项
* `slice()`函数必须用于返回仅包含`warm` `sunny`的数组。
* 因此,必须将两个参数传递给`slice()`函数。第一个参数必须是您希望子字符串开始的索引。第二个参数必须是子字符串结束的索引。
* 注意:第二个参数将在该精确索引处结束子字符串。
## 例:
```javascript
return arr.slice(1,4);
/* This will return a substring consisting of indexs [1,2,3]
Note: arr[4] is NOT included.
```
## 解:
```javascript
function forecast(arr) {
// change code below this line
return arr.slice(2,4);
}
// do not change code below this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
```

View File

@@ -0,0 +1,28 @@
---
title: Create complex multi-dimensional arrays
localeTitle: 创建复杂的多维数组
---
## 创建复杂的多维数组
* 第一个字符串 - `deep` - 必须插入三层深。这意味着正好在三组`[square-brackets]`
```javascript
let threeLevelArray = ["first level", ["Two levels deep", ["Three levels deep"]]];
```
* 使用这种逻辑插入串`deep` `deeper``deepest`分别深处矩阵三个层次深,四个层次深,五个级别。
## 解:
```javascript
let myNestedArray = [
// change code below this line
['unshift', false, 1, 2, 3, 'complex', 'nested'],
['loop', 'shift', 6, 7, 1000, 'method'],
['concat', false, true, 'spread', 'array',["deep"]],
['mutate', 1327.98, 'splice', 'slice', 'push', [["deeper"]]],
['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth', [[["deepest"]]] ]
// change code above this line
];
```

View File

@@ -0,0 +1,42 @@
---
title: Generate an Array of All Object Keys with Object.keys()
localeTitle: 使用Object.keys生成所有对象键的数组
---
## 使用Object.keys生成所有对象键的数组
### 方法:
* 要返回用户数组, `Object.keys()`方法必须采用争论。
* 可以使用单行返回语句来解决此挑战。
### 解:
```javascript
let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};
function getArrayOfUsers(obj) {
// change code below this line
return Object.keys(obj);
// change code above this line
}
console.log(getArrayOfUsers(users));
```

View File

@@ -0,0 +1,11 @@
---
title: Basic Data Structures
localeTitle: 基本数据结构
---
## 基本数据结构
这是一个存根。 [帮助我们的社区扩展它](https://github.com/freecodecamp/guides/tree/master/src/pages/mathematics/quadratic-equations/index.md) 。
[这种快速风格指南有助于确保您的拉取请求被接受](https://github.com/freecodecamp/guides/blob/master/README.md) 。
#### 更多信息:

View File

@@ -0,0 +1,54 @@
---
title: Iterate Through All an Array's Items Using For Loops
localeTitle: 使用for循环遍历所有数组的项目
---
## 使用for循环遍历所有数组的项目
## 提示1
* 必须使用嵌套的`for`循环来搜索数组中的每个元素。
```javascript
for (let i = 0; i < arr.length; i++) {
```
\`
## 提示2
* 然后必须将数组的每个元素与通过`filteredArray()`函数传递的`elem`参数进行比较。
```javascript
if (arr[i].indexOf(elem)==-1){
```
## 提示3
* 如果未找到匹配,则`newArr`会添加整个子阵列。 `push()`函数在这里非常有用。
```javascript
newArr.push(arr[i]);
```
* 将整个子阵列添加到`newArr` ,循环继续下一个元素。
## 解:
```javascript
function filteredArray(arr, elem) {
let newArr = [];
// change code below this line
for (let i = 0; i < arr.length; i++) {
if (arr[i].indexOf(elem)==-1){ //Checks every parameter for the element and if is NOT there continues the code
newArr.push(arr[i]); //Inserts the element of the array in the new filtered array
};
};
// change code above this line
return newArr;
};
// change code here to test different cases:
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
```

View File

@@ -0,0 +1,45 @@
---
title: Modify an Array Stored in an Object
localeTitle: 修改存储在对象中的数组
---
## 修改存储在对象中的数组
### 方法:
* 该函数只需两行代码即可编写。
* 第一行应该只使用`push()`函数将`friend`参数添加到`user.data.friend`的数组中。第二行将返回修改后的数组。
* 请记住,必须使用`addFriend()`函数的第一个参数引用`user`
### 解:
```javascript
let user = {
name: 'Kenneth',
age: 28,
data: {
username: 'kennethCodesAllDay',
joinDate: 'March 26, 2016',
organization: 'freeCodeCamp',
friends: [
'Sam',
'Kira',
'Tomo'
],
location: {
city: 'San Francisco',
state: 'CA',
country: 'USA'
}
}
};
function addFriend(userObj, friend) {
// change code below this line
userObj.data.friends.push(friend);
return userObj.data.friends;
// change code above this line
}
console.log(addFriend(user, 'Pete'));
```

View File

@@ -0,0 +1,46 @@
---
title: Modify an Object Nested Within an Object
localeTitle: 修改嵌套在对象中的对象
---
## 修改嵌套在对象中的对象
方法:
* 请记住,您想要更改的对象是两个级别, `dot-notation`在此实例中更容易使用。
* 只需定义对象,然后使用`dot-notation`访问第二个对象,最后使用您想要修改的最终元素。
## 例:
```javascript
let myObject = {
level_1: 'outside',
first_level_object: {
level_2: '2 levels deep',
second_level_object: {
level_3: '3 levels deep'
}
}
};
//The following line of code will modify the data found in level_2.
myObject.first_level_object.level_2 = 'level-2 has been reached';
```
## 解:
```javascript
let userActivity = {
id: 23894201352,
date: 'January 1, 2017',
data: {
totalUsers: 51,
online: 42
}
};
// change code below this line
userActivity.data.online = 45;
// change code above this line
console.log(userActivity);
```

View File

@@ -0,0 +1,21 @@
---
title: Remove Items from an Array with pop() and shift()
localeTitle: 使用pop和shift从数组中删除项
---
## 使用pop和shift从数组中删除项
* 必须使用`popped``shifted`变量调用和初始化`.pop()`方法和`.shift()`方法,以从函数返回正确的答案。
## 解:
```javascript
function popShift(arr) {
let popped = arr.pop();
let shifted = arr.shift();
return [shifted, popped];
}
// do not change code below this line
console.log(popShift(['challenge', 'is', 'not', 'complete']));
```

View File

@@ -0,0 +1,23 @@
---
title: Remove Items Using splice()
localeTitle: 使用splice删除项目
---
## 使用splice删除项目
* 必须在`arr`数组上调用`splice()`函数以便从数组的中心删除1个或多个元素。
* 数组`arr`目前的`arr`值为16.只需删除返回10所需的任意数量的变量。
## 解:
```javascript
function sumOfTen(arr) {
// change code below this line
arr.splice(1,2);
// change code above this line
return arr.reduce((a, b) => a + b);
}
// do not change code below this line
console.log(sumOfTen([2, 5, 1, 5, 2, 1]));
```

View File

@@ -0,0 +1,28 @@
---
title: Use an Array to Store a Collection of Data
localeTitle: 使用数组存储数据集合
---
## 使用数组存储数据集合
### 方法:
* 在JS中Arrays是最常用的数据结构之一。与其他语言不同JS中的数组可以存储不同的数据类型也可以在运行时更改它们的大小因此也称为“动态数组”。它们也被编入索引。
* 数组可以用不同的方式初始化:
1. 数组文字
2. 数组构造函数
* 在这个挑战中,我们将专注于数组文字。要初始化一个数组,我们只需`let arr = [];`
* 我们可以通过访问索引来为这个数组添加值,例如: `javascript let arr = []; arr[0] = "hello"; console.log(arr); // ["hello"]`
* 我们在声明它时也可以初始化数组中的值,例如: `javascript let arr = [1, 2, 3, "John"];`
* 在此挑战中您需要创建一个至少包含5个元素且至少包含一个字符串一个数字和一个布尔值的数组。
### 解:
```js
let yourArray = ["a", 2, true, "c", null, {name: "john"}];
```
### 资源
进一步阅读[MDN上的](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)数组。

View File

@@ -0,0 +1,27 @@
---
title: Use the delete Keyword to Remove Object Properties
localeTitle: 使用删除关键字删除对象属性
---
## 使用删除关键字删除对象属性
[Developer.mozilla.org](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete)提供了有关delete运算符的综合教程。
### 解:
```javascript
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
// change code below this line
delete foods.oranges;
delete foods.plums;
delete foods.strawberries;
// change code above this line
console.log(foods);
```