chore(i18n,curriculum): update translations (#43881)

This commit is contained in:
camperbot
2021-10-18 08:17:43 -07:00
committed by GitHub
parent e8e64318b3
commit 0654bd92b0
67 changed files with 513 additions and 402 deletions

View File

@ -1,6 +1,6 @@
---
id: 8d5123c8c441eddfaeb5bdef
title: Implement Bubble Sort
title: 实现冒泡排序
challengeType: 1
forumTopicId: 301612
dashedName: implement-bubble-sort
@ -8,23 +8,23 @@ dashedName: implement-bubble-sort
# --description--
This is the first of several challenges on sorting algorithms. Given an array of unsorted items, we want to be able to return a sorted array. We will see several different methods to do this and learn some tradeoffs between these different approaches. While most modern languages have built-in sorting methods for operations like this, it is still important to understand some of the common basic approaches and learn how they can be implemented.
这是排序算法的几个挑战中的第一个。 给定一组未排序的元素数组,我们希望能够返回已排序的数组。 我们将看到几种不同的方法来实现这一点,并学习这些不同方法之间的一些权衡。 虽然大多数现代语言都有内置的排序方法来完成这样的操作,但了解一些常见的基本方法并了解如何实现它们仍然很重要。
Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and 'bubbles up' unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.
在这里我们将看到冒泡排序。 冒泡排序方法从未排序数组的开头开始,并向末端“冒泡”未排序的值,遍历数组直到它完全排序。 它是这样实现的:比较相邻的元素,如果它们的顺序不对,就交换它们。 该方法继续循环遍历数组,直到没有发生交换,此时数组已被排序。
This method requires multiple iterations through the array and for average and worst cases has quadratic time complexity. While simple, it is usually impractical in most situations.
这种方法需要对数组进行多次循环,对于平均和最坏的情况来说,其时间复杂性为二次方。 虽然简单,但在大多数情况下通常不切实际。
**Instructions:** Write a function `bubbleSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
**说明:**写一个 `bubbleSort` 函数,它将一个整数数组作为输入,并返回一个数组,其中的整数元素以从小到大的顺序排列。
# --hints--
`bubbleSort` should be a function.
`bubbleSort` 应该是一个函数。
```js
assert(typeof bubbleSort == 'function');
```
`bubbleSort` should return a sorted array (least to greatest).
`bubbleSort` 应该返回一个已排序的数组(从小到大)。
```js
assert(
@ -52,7 +52,7 @@ assert(
);
```
`bubbleSort` should return an array that is unchanged except for order.
`bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` 应返回一个除顺序外没有变化的数组。
```js
assert.sameMembers(
@ -79,7 +79,7 @@ assert.sameMembers(
);
```
`bubbleSort` should not use the built-in `.sort()` method.
`bubbleSort` 不应使用内置的 `.sort()` 方法。
```js
assert(isBuiltInSortUsed());
@ -113,8 +113,6 @@ function bubbleSort(array) {
return array;
// Only change code above this line
}
bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```
# --solutions--

View File

@ -1,6 +1,6 @@
---
id: 587d8259367417b2b2512c86
title: Implement Insertion Sort
title: 实现插入排序
challengeType: 1
forumTopicId: 301613
dashedName: implement-insertion-sort
@ -8,19 +8,19 @@ dashedName: implement-insertion-sort
# --description--
The next sorting method we'll look at is insertion sort. This method works by building up a sorted array at the beginning of the list. It begins the sorted array with the first element. Then it inspects the next element and swaps it backwards into the sorted array until it is in sorted position. It continues iterating through the list and swapping new items backwards into the sorted portion until it reaches the end. This algorithm has quadratic time complexity in the average and worst cases.
我们将要研究的下一个排序方法是插入排序。 此方法的工作原理是通过在数组的开头构建排序数组。 它从第一个元素开始排序数组。 然后,它检查下一个元素并将其向后交换到已排序的数组中,直到它处于已排序的位置为止。 它继续遍历列表,并将新项目向后交换到已排序的部分中,直到到达末尾为止。 这种算法在平均和最坏的情况下都有二次方的时间复杂性。
**Instructions:** Write a function `insertionSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
**说明:** 编写一个函数`insertionSort` ,它将一个整数数组作为输入,并按照从最小到最大的排序顺序返回这些整数的数组。
# --hints--
`insertionSort` should be a function.
`insertionSort` 应该是一个函数。
```js
assert(typeof insertionSort == 'function');
```
`insertionSort` should return a sorted array (least to greatest).
`insertionSort` 应该返回一个排序的数组(从最小到最大)。
```js
assert(
@ -48,7 +48,7 @@ assert(
);
```
`insertionSort` should return an array that is unchanged except for order.
`insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` 应返回一个除顺序外没有变化的数组。
```js
assert.sameMembers(
@ -75,7 +75,13 @@ assert.sameMembers(
);
```
`insertionSort` should not use the built-in `.sort()` method.
`insertionSort([5, 4, 33, 2, 8])` 应返回 `[2, 4, 5, 8, 33]`
```js
assert.deepEqual(insertionSort([5, 4, 33, 2, 8]), [2, 4, 5, 8, 33])
```
`insertionSort` 不应使用内置的 `.sort()` 方法。
```js
assert(isBuiltInSortUsed());
@ -109,8 +115,6 @@ function insertionSort(array) {
return array;
// Only change code above this line
}
insertionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```
# --solutions--

View File

@ -1,6 +1,6 @@
---
id: 587d825c367417b2b2512c8f
title: Implement Merge Sort
title: 实现归并排序
challengeType: 1
forumTopicId: 301614
dashedName: implement-merge-sort
@ -8,27 +8,27 @@ dashedName: implement-merge-sort
# --description--
Another common intermediate sorting algorithm is merge sort. Like quick sort, merge sort also uses a divide-and-conquer, recursive methodology to sort an array. It takes advantage of the fact that it is relatively easy to sort two arrays as long as each is sorted in the first place. But we'll start with only one array as input, so how do we get to two sorted arrays from that? Well, we can recursively divide the original input in two until we reach the base case of an array with one item. A single-item array is naturally sorted, so then we can start combining. This combination will unwind the recursive calls that split the original array, eventually producing a final sorted array of all the elements. The steps of merge sort, then, are:
另一种常见的中间排序算法是归并排序。 像快速排序一样,合并排序也使用分而治之的递归方法对数组进行排序。 它基于这样一个事实:要将两个已经排好序的数组排在一起,是相对容易的。 但是我们只从一个数组作为输入开始,那么我们如何从中获得两个已排序的数组呢? 好吧,我们可以递归地将原始输入分成两部分,直到我们到达每个数组只有一个元素的基本情况。 单项数组是自然排序的,因此我们可以开始组合。 这个组合将展开拆分原始数组的递归调用,最终生成所有元素的最终排序数组。 合并排序的步骤如下:
**1)** Recursively split the input array in half until a sub-array with only one element is produced.
**1)** 将输入数组递归地分成两部分,直到生成仅包含一个元素的子数组。
**2)** Merge each sorted sub-array together to produce the final sorted array.
**2)** 将每个已排序的子数组合并在一起以生成最终的排序的数组。
Merge sort is an efficient sorting method, with time complexity of *O(nlog(n))*. This algorithm is popular because it is performant and relatively easy to implement.
合并排序是一种有效的排序方法,时间复杂度为 *O(nlog(n))* 。 该算法很受欢迎,因为它性能高且易于实现。
As an aside, this will be the last sorting algorithm we cover here. However, later in the section on tree data structures we will describe heap sort, another efficient sorting method that requires a binary heap in its implementation.
顺便说一句,这将是我们在此处介绍的最后一种排序算法。 但是,稍后在关于树型数据结构的部分中,我们将描述堆排序,这是另一种在其实现中需要二进制堆的有效排序方法。
**Instructions:** Write a function `mergeSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. A good way to implement this is to write one function, for instance `merge`, which is responsible for merging two sorted arrays, and another function, for instance `mergeSort`, which is responsible for the recursion that produces single-item arrays to feed into merge. Good luck!
**说明:** 编写一个函数 `mergeSort`,它以整数数组作为输入,并按从最小到最大的排序顺序返回这些整数的数组。 实现这一点的一个好方法是编写一个函数,例如 `merge`,它负责合并两个已排序的数组;以及另一个函数,例如 `mergeSort`,它负责递归,生成单项数组以提供给 merge。 祝你好运!
# --hints--
`mergeSort` should be a function.
`mergeSort` 应该是一个函数。
```js
assert(typeof mergeSort == 'function');
```
`mergeSort` should return a sorted array (least to greatest).
`mergeSort` 应该返回一个已排序的数组(从小到大)。
```js
assert(
@ -56,7 +56,7 @@ assert(
);
```
`mergeSort` should return an array that is unchanged except for order.
`mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` 应返回一个除顺序外没有变化的数组。
```js
assert.sameMembers(
@ -83,7 +83,7 @@ assert.sameMembers(
);
```
`mergeSort` should not use the built-in `.sort()` method.
`mergeSort` 不应使用内置的 `.sort()` 方法。
```js
assert(isBuiltInSortUsed());
@ -117,8 +117,6 @@ function mergeSort(array) {
return array;
// Only change code above this line
}
mergeSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```
# --solutions--

View File

@ -1,6 +1,6 @@
---
id: 587d8259367417b2b2512c85
title: Implement Selection Sort
title: 实现选择排序
challengeType: 1
forumTopicId: 301616
dashedName: implement-selection-sort
@ -8,19 +8,19 @@ dashedName: implement-selection-sort
# --description--
Here we will implement selection sort. Selection sort works by selecting the minimum value in a list and swapping it with the first value in the list. It then starts at the second position, selects the smallest value in the remaining list, and swaps it with the second element. It continues iterating through the list and swapping elements until it reaches the end of the list. Now the list is sorted. Selection sort has quadratic time complexity in all cases.
这里我们将实现选择排序。 选择排序的工作原理是选择列表中的最小值并与列表中的第一个值进行交换。 然后它从第二个位置开始,选择剩余列表中的最小值,并将其与第二个元素交换。 它继续遍历列表并交换元素,直到它到达列表的末尾。 现在列表已排序。 在所有情况下,选择排序都具有二次方的时间复杂度。
**Instructions**: Write a function `selectionSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
**说明**:编写一个 `selectionSort` 函数,它将一个整数数组作为输入,并按照从最小到最大的排序顺序返回这些整数的数组。
# --hints--
`selectionSort` should be a function.
`selectionSort` 应该是一个函数。
```js
assert(typeof selectionSort == 'function');
```
`selectionSort` should return a sorted array (least to greatest).
`selectionSort` 应该返回一个排序的数组(从最小到最大)。
```js
assert(
@ -48,7 +48,7 @@ assert(
);
```
`selectionSort` should return an array that is unchanged except for order.
`selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` 应返回一个除顺序外没有变化的数组。
```js
assert.sameMembers(
@ -75,7 +75,7 @@ assert.sameMembers(
);
```
`selectionSort` should not use the built-in `.sort()` method.
`selectionSort` 不应使用内置的 `.sort()` 方法。
```js
assert(isBuiltInSortUsed());
@ -109,9 +109,6 @@ function selectionSort(array) {
return array;
// Only change code above this line
}
selectionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```
# --solutions--

View File

@ -1,6 +1,6 @@
---
id: a7bf700cd123b9a54eef01d5
title: No Repeats Please
title: 请不要重复
challengeType: 5
forumTopicId: 16037
dashedName: no-repeats-please
@ -8,67 +8,67 @@ dashedName: no-repeats-please
# --description--
Return the number of total permutations of the provided string that don't have repeated consecutive letters. Assume that all characters in the provided string are each unique.
返回没有重复连续字母的提供字符串的总排列数。 假设提供的字符串中的所有字符都是唯一的。
For example, `aab` should return 2 because it has 6 total permutations (`aab`, `aab`, `aba`, `aba`, `baa`, `baa`), but only 2 of them (`aba` and `aba`) don't have the same letter (in this case `a`) repeating.
例如,`aab` 应该返回 2因为它有 6 个排列(`aab``aab``aba``aba``baa` `baa`),但其中只有 2 个(`aba` `aba`)没有重复相同字符(即 `a`)。
# --hints--
`permAlone("aab")` should return a number.
`permAlone("aab")` 应返回 2。
```js
assert.isNumber(permAlone('aab'));
```
`permAlone("aab")` should return 2.
`permAlone("aab")` 应该返回 2
```js
assert.strictEqual(permAlone('aab'), 2);
```
`permAlone("aaa")` should return 0.
`permAlone("aaa")` 应该返回 0
```js
assert.strictEqual(permAlone('aaa'), 0);
```
`permAlone("aabb")` should return 8.
`permAlone("aabb")`应返回 8
```js
assert.strictEqual(permAlone('aabb'), 8);
```
`permAlone("abcdefa")` should return 3600.
`permAlone("abcdefa")`应返回 3600
```js
assert.strictEqual(permAlone('abcdefa'), 3600);
```
`permAlone("abfdefa")` should return 2640.
`permAlone("abfdefa")`应该返回 2640
```js
assert.strictEqual(permAlone('abfdefa'), 2640);
```
`permAlone("zzzzzzzz")` should return 0.
`permAlone("zzzzzzzz")` 应返回 0
```js
assert.strictEqual(permAlone('zzzzzzzz'), 0);
```
`permAlone("a")` should return 1.
`permAlone("a")` 应该返回 1
```js
assert.strictEqual(permAlone('a'), 1);
```
`permAlone("aaab")` should return 0.
`permAlone("aaab")` 应该返回 0
```js
assert.strictEqual(permAlone('aaab'), 0);
```
`permAlone("aaabb")` should return 12.
`permAlone("aaabb")` 应返回 12.
```js
assert.strictEqual(permAlone('aaabb'), 12);

View File

@ -1,6 +1,6 @@
---
id: a3f503de51cfab748ff001aa
title: Pairwise
title: 成对
challengeType: 5
forumTopicId: 301617
dashedName: pairwise
@ -8,57 +8,57 @@ dashedName: pairwise
# --description--
Given an array `arr`, find element pairs whose sum equal the second argument `arg` and return the sum of their indices.
给定一个数组 `arr` ,找到其中总和等于第二个参数 `arg` 的元素对,并返回它们的索引之和。
You may use multiple pairs that have the same numeric elements but different indices. Each pair should use the lowest possible available indices. Once an element has been used it cannot be reused to pair with another element. For instance, `pairwise([1, 1, 2], 3)` creates a pair `[2, 1]` using the 1 at index 0 rather than the 1 at index 1, because 0+2 < 1+2.
你可以使用具有相同数字元素但索引不同的多个对。 每对应使用尽可能低的索引。 一旦元素被使用,它就不能被重用来与另一个元素配对。 例如, `pairwise([1, 1, 2], 3)` 使用索引为 0 的 1而不是索引为 1 的 1 来创建一对 `[2, 1]`,因为 0 + 2 < 1 + 2。
For example `pairwise([7, 9, 11, 13, 15], 20)` returns `6`. The pairs that sum to 20 are `[7, 13]` and `[9, 11]`. We can then write out the array with their indices and values.
例如, `pairwise([7, 9, 11, 13, 15], 20)` 返回 `6`。 总和为 20 的对是 `[7, 13]` `[9, 11]`。 然后我们可以用它们的索引和值写出数组。
<div style='margin-left: 2em;'>
| Index | 0 | 1 | 2 | 3 | 4 |
| 索引 | 0 | 1 | 2 | 3 | 4 |
| ----- | - | - | -- | -- | -- |
| Value | 7 | 9 | 11 | 13 | 15 |
| | 7 | 9 | 11 | 13 | 15 |
</div>
Below we'll take their corresponding indices and add them.
接下来,我们将获取它们的相应索引并添加它们。
<div style='margin-left: 2em;'>
7 + 13 = 20 → Indices 0 + 3 = 3
9 + 11 = 20 → Indices 1 + 2 = 3
3 + 3 = 6 → Return `6`
7 + 13 = 20 → 索引 0 + 3 = 3
9 + 11 = 20 → 索引 1 + 2 = 3
3 + 3 = 6 →返回 `6`
</div>
# --hints--
`pairwise([1, 4, 2, 3, 0, 5], 7)` should return 11.
`pairwise([1, 4, 2, 3, 0, 5], 7)` 应该返回 11
```js
assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11);
```
`pairwise([1, 3, 2, 4], 4)` should return 1.
`pairwise([1, 3, 2, 4], 4)` 应返回 1
```js
assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1);
```
`pairwise([1, 1, 1], 2)` should return 1.
`pairwise([1, 1, 1], 2)` 应该返回 1
```js
assert.deepEqual(pairwise([1, 1, 1], 2), 1);
```
`pairwise([0, 0, 0, 0, 1, 1], 1)` should return 10.
`pairwise([0, 0, 0, 0, 1, 1], 1)` 应该返回10
```js
assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10);
```
`pairwise([], 100)` should return 0.
`pairwise([], 100)` 应该返回 0
```js
assert.deepEqual(pairwise([], 100), 0);