chore(i8n,learn): processed translations (#41350)

* chore(i8n,learn): processed translations

* fix: restore deleted test

* fix: revert casing change

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
This commit is contained in:
Nicholas Carrigan (he/him)
2021-03-04 09:49:46 -08:00
committed by GitHub
parent 8e4ada8f2d
commit aff0ea700d
69 changed files with 606 additions and 598 deletions

View File

@ -1,6 +1,6 @@
---
id: 587d7b7c367417b2b2512b1a
title: Access Property Names with Bracket Notation
title: 使用方括号访问属性名称
challengeType: 1
forumTopicId: 301150
dashedName: access-property-names-with-bracket-notation
@ -8,28 +8,28 @@ dashedName: access-property-names-with-bracket-notation
# --description--
In the first object challenge we mentioned the use of bracket notation as a way to access property values using the evaluation of a variable. For instance, imagine that our `foods` object is being used in a program for a supermarket cash register. We have some function that sets the `selectedFood` and we want to check our `foods` object for the presence of that food. This might look like:
在关于对象的第一个挑战中,我们提到可以在一对方括号中用一个变量作为属性名来访问属性的值。 假设一个超市收银台程序中有一个 `foods` 对象, 并且有一个函数会设置 `selectedFood`;如果我们需要查询 `foods` 对象中,某种食物是否存在, 可以这样实现:
```js
let selectedFood = getCurrentFood(scannedItem);
let inventory = foods[selectedFood];
```
This code will evaluate the value stored in the `selectedFood` variable and return the value of that key in the `foods` object, or `undefined` if it is not present. Bracket notation is very useful because sometimes object properties are not known before runtime or we need to access them in a more dynamic way.
上述代码会先读取 `selectedFood` 变量的值,并返回 `foods` 对象中以该值命名的属性所对应的属性值。 若没有以该值命名的属性,则会返回 `undefined`。 有时候对象的属性名在运行之前是不确定的,或者我们需要动态地访问对象的属性值。在这些场景下,方括号表示法就变得十分有用。
# --instructions--
We've defined a function, `checkInventory`, which receives a scanned item as an argument. Return the current value of the `scannedItem` key in the `foods` object. You can assume that only valid keys will be provided as an argument to `checkInventory`.
我们已经定义了 `checkInventory` 函数,它接受一个被扫描到的商品名作为输入参数。 请让这个函数返回 `foods` 对象中,以 `scannedItem` 的值所命名的属性对应的属性值。 在本挑战中,只有合理有效的属性名会作为参数传入 `checkInventory`,因此你不需要处理参数无效的情况。
# --hints--
`checkInventory` should be a function.
`checkInventory` 应是一个函数。
```js
assert.strictEqual(typeof checkInventory, 'function');
```
The `foods` object should have only the following key-value pairs: `apples: 25`, `oranges: 32`, `plums: 28`, `bananas: 13`, `grapes: 35`, `strawberries: 27`.
`foods` 对象应只包含以下键值对:`apples: 25``oranges: 32``plums: 28``bananas: 13``grapes: 35``strawberries: 27`
```js
assert.deepEqual(foods, {
@ -42,19 +42,19 @@ assert.deepEqual(foods, {
});
```
`checkInventory("apples")` should return `25`.
`checkInventory("apples")` 应返回 `25`
```js
assert.strictEqual(checkInventory('apples'), 25);
```
`checkInventory("bananas")` should return `13`.
`checkInventory("bananas")` 应返回 `13`
```js
assert.strictEqual(checkInventory('bananas'), 13);
```
`checkInventory("strawberries")` should return `27`.
`checkInventory("strawberries")` 应返回 `27`
```js
assert.strictEqual(checkInventory('strawberries'), 27);

View File

@ -1,6 +1,6 @@
---
id: 587d7b7d367417b2b2512b1e
title: Generate an Array of All Object Keys with Object.keys()
title: 使用 Object.keys() 生成由对象的所有属性组成的数组
challengeType: 1
forumTopicId: 301160
dashedName: generate-an-array-of-all-object-keys-with-object-keys
@ -8,15 +8,15 @@ dashedName: generate-an-array-of-all-object-keys-with-object-keys
# --description--
We can also generate an array which contains all the keys stored in an object using the `Object.keys()` method and passing in an object as the argument. This will return an array with strings representing each property in the object. Again, there will be no specific order to the entries in the array.
我们可以给 `Object.keys()` 方法传入一个对象作为参数,来生成包含对象所有键的数组。 这会返回一个由对象中所有属性(字符串)组成的数组。 需要注意的是,数组中元素的顺序是不确定的。
# --instructions--
Finish writing the `getArrayOfUsers` function so that it returns an array containing all the properties in the object it receives as an argument.
请完成 `getArrayOfUsers` 函数的实现,使其返回一个由输入对象中的所有属性所组成的数组。
# --hints--
The `users` object should only contain the keys `Alan`, `Jeff`, `Sarah`, and `Ryan`
`users` 对象应该只包含 `Alan``Jeff``Sarah``Ryan` 这 4 个属性。
```js
assert(
@ -28,7 +28,7 @@ assert(
);
```
The `getArrayOfUsers` function should return an array which contains all the keys in the `users` object
`getArrayOfUsers` 函数应返回一个包含 `users` 对象中所有属性的数组。
```js
assert(

View File

@ -1,6 +1,6 @@
---
id: 587d7b7d367417b2b2512b1f
title: Modify an Array Stored in an Object
title: 修改存储在对象中的数组
challengeType: 1
forumTopicId: 301163
dashedName: modify-an-array-stored-in-an-object
@ -8,21 +8,21 @@ dashedName: modify-an-array-stored-in-an-object
# --description--
Now you've seen all the basic operations for JavaScript objects. You can add, modify, and remove key-value pairs, check if keys exist, and iterate over all the keys in an object. As you continue learning JavaScript you will see even more versatile applications of objects. Additionally, the Data Structures lessons located in the Coding Interview Prep section of the curriculum also cover the ES6 <dfn>Map</dfn> and <dfn>Set</dfn> objects, both of which are similar to ordinary objects but provide some additional features. Now that you've learned the basics of arrays and objects, you're fully prepared to begin tackling more complex problems using JavaScript!
我们已经学习了 JavaScript 对象的这些基本操作: 添加、修改、移除键值对、检查某个属性是否存在、遍历对象的所有属性。 在继续学习 JavaScript 的过程中,我们会了解对象的更多用法。 另外,在之后的数据结构课程中,我们还会学习 ES6 <dfn>Map</dfn> <dfn>Set</dfn>。 这两种数据结构与我们现在学到的对象十分类似,但它们在对象的基础上提供了一些额外的功能。 目前,我们已经学习了数组和对象的基础知识,让我们试着来用所学的知识解决一些更复杂的问题。
# --instructions--
Take a look at the object we've provided in the code editor. The `user` object contains three keys. The `data` key contains five keys, one of which contains an array of `friends`. From this, you can see how flexible objects are as data structures. We've started writing a function `addFriend`. Finish writing it so that it takes a `user` object and adds the name of the `friend` argument to the array stored in `user.data.friends` and returns that array.
请看一下代码编辑器中我们为你写好的对象。 `user` 对象包含 3 个属性; `data` 对象包含 5 个属性,其中包含一个叫做 `friends` 的数组。 这就是对象作为数据结构所展现出的灵活性。 我们已经写好了 `addFriend` 函数的一部分, 请你完成这个函数,使其接受一个 `user` 对象,将 `friend` 参数中的名字添加到 `user.data.friends` 数组中并返回该数组。
# --hints--
The `user` object should have `name`, `age`, and `data` keys.
`user` 对象应该包含 `name``age` `data` 三个属性。
```js
assert('name' in user && 'age' in user && 'data' in user);
```
The `addFriend` function should accept a `user` object and a `friend` string as arguments and add the friend to the array of `friends` in the `user` object.
`addFriend` 函数应该接受一个 `user` 对象和一个 `friend` 字符串作为输入参数,并将这个字符串插入到 `user` 对象的 `friends` 数组中。
```js
assert(
@ -35,7 +35,7 @@ assert(
);
```
`addFriend(user, "Pete")` should return `["Sam", "Kira", "Tomo", "Pete"]`.
`addFriend(user, "Pete")` 应该返回 `["Sam", "Kira", "Tomo", "Pete"]`
```js
assert.deepEqual(

View File

@ -1,6 +1,6 @@
---
id: 587d7b7c367417b2b2512b19
title: Modify an Object Nested Within an Object
title: 修改嵌套在对象中的对象
challengeType: 1
forumTopicId: 301164
dashedName: modify-an-object-nested-within-an-object
@ -8,7 +8,7 @@ dashedName: modify-an-object-nested-within-an-object
# --description--
Now let's take a look at a slightly more complex object. Object properties can be nested to an arbitrary depth, and their values can be any type of data supported by JavaScript, including arrays and even other objects. Consider the following:
现在我们来看一个稍复杂的对象。 在对象中,我们也可以嵌套任意层数的对象,对象的属性值可以是 JavaScript 支持的任意类型,包括数组和其他对象。 请看以下例子:
```js
let nestedObject = {
@ -26,7 +26,7 @@ let nestedObject = {
};
```
`nestedObject` has three properties: `id` (value is a number), `date` (value is a string), and `data` (value is an object with its nested structure). While structures can quickly become complex, we can still use the same notations to access the information we need. To assign the value `10` to the `busy` property of the nested `onlineStatus` object, we use dot notation to reference the property:
`nestedObject` 有 3 个属性:`id`(属性值为数字)、`date`(属性值为字符串)、`data`(属性值为嵌套的对象)。 虽然对象中的数据可能很复杂,我们仍能使用上一个挑战中讲到的写法来访问我们需要的信息。 如果我们想把嵌套在 `onlineStatus``busy` 的属性值改为 `10`,可以用点号表示法来这样实现:
```js
nestedObject.data.onlineStatus.busy = 10;
@ -34,11 +34,11 @@ nestedObject.data.onlineStatus.busy = 10;
# --instructions--
Here we've defined an object `userActivity`, which includes another object nested within it. Set the value of the `online` key to `45`.
我们已经定义了一个 `userActivity` 对象,它包含了另一个对象。 请将 `online` 的属性值改为 `45`
# --hints--
`userActivity` should have `id`, `date` and `data` properties.
`userActivity` 应包含 `id``date` `data` 属性。
```js
assert(
@ -46,19 +46,19 @@ assert(
);
```
`userActivity` should have a `data` key set to an object with keys `totalUsers` and `online`.
`userActivity` 应包含 `data` 属性,其属性值应为包含 `totalUsers` `online` 属性的对象。
```js
assert('totalUsers' in userActivity.data && 'online' in userActivity.data);
```
The `online` property nested in the `data` key of `userActivity` should be set to `45`
`userActivity``data` 属性值中的 `online` 属性值应被改为 `45`
```js
assert(userActivity.data.online === 45);
```
The `online` property should be set using dot or bracket notation.
应使用点号表示法或方括号表示法来修改 `online` 属性值。
```js
assert.strictEqual(code.search(/online: 45/), -1);

View File

@ -1,6 +1,6 @@
---
id: 587d7b7c367417b2b2512b1b
title: Use the delete Keyword to Remove Object Properties
title: 使用 delete 关键字删除对象属性
challengeType: 1
forumTopicId: 301168
dashedName: use-the-delete-keyword-to-remove-object-properties
@ -8,11 +8,11 @@ dashedName: use-the-delete-keyword-to-remove-object-properties
# --description--
Now you know what objects are and their basic features and advantages. In short, they are key-value stores which provide a flexible, intuitive way to structure data, ***and***, they provide very fast lookup time. Throughout the rest of these challenges, we will describe several common operations you can perform on objects so you can become comfortable applying these useful data structures in your programs.
现在我们已经学习了什么是对象以及对象的基本特性和用途。 总之,对象是以键值对的形式,灵活、直观地存储结构化数据的一种方式,***而且***,通过对象的属性查找属性值是速度很快的操作。 在本章余下的挑战中,我们来了解一下对象的几种常用操作,这样你能更好地在代码中使用这个十分有用的数据结构:对象。
In earlier challenges, we have both added to and modified an object's key-value pairs. Here we will see how we can *remove* a key-value pair from an object.
在之前的挑战中,我们已经试过添加和修改对象中的键值对。 现在我们来看看如何从一个对象中*移除*一个键值对。
Let's revisit our `foods` object example one last time. If we wanted to remove the `apples` key, we can remove it by using the `delete` keyword like this:
我们再来回顾一下上一个挑战中的 `foods` 对象。 如果我们想移除 `apples` 属性,可以像这样使用 `delete` 关键字:
```js
delete foods.apples;
@ -20,11 +20,11 @@ delete foods.apples;
# --instructions--
Use the delete keyword to remove the `oranges`, `plums`, and `strawberries` keys from the `foods` object.
请使用 delete 关键字来移除 `foods` 中的 `oranges``plums` `strawberries` 属性。
# --hints--
The `foods` object should only have three keys: `apples`, `grapes`, and `bananas`.
`foods` 对象应只包含 3 个属性:`apples``grapes` `bananas`
```js
assert(
@ -35,7 +35,7 @@ assert(
);
```
The `oranges`, `plums`, and `strawberries` keys should be removed using `delete`.
应使用 `delete` 关键字来移除 `oranges``plums` `strawberries` 属性。
```js
assert(