chore(i8n,learn): processed translations

This commit is contained in:
Crowdin Bot
2021-02-06 04:42:36 +00:00
committed by Mrugesh Mohapatra
parent 15047f2d90
commit e5c44a3ae5
3274 changed files with 172122 additions and 14164 deletions

View File

@ -1,78 +1,84 @@
---
id: a3f503de51cf954ede28891d
title: 找到对称差异
title: Find the Symmetric Difference
challengeType: 5
videoUrl: ''
forumTopicId: 301611
dashedName: find-the-symmetric-difference
---
# --description--
创建一个带有两个或更多数组的函数,并返回所提供数组的<dfn>对称差</dfn> `△``⊕` )数组。给定两个集合(例如集合`A = {1, 2, 3}`并且集合`B = {2, 3, 4}` ),两个集合的数学术语“对称差异”是在任一集合中的元素集合。两组,但两者都没有( `A △ B = C = {1, 4}` )。对于你所采取的每一个额外的对称差异(比如在集合`D = {2, 3}` ),你应该得到具有两个集合中的任何一个但不是两个集合的元素的集合( `C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}` )。结果数组必须仅包含唯一值( *不重复* )。如果卡住,请记得使用[Read-Search-Ask](https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514) 。尝试配对程序。编写自己的代码。
The mathematical term <dfn>symmetric difference</dfn> (`△` or `⊕`) of two sets is the set of elements which are in either of the two sets but not in both. For example, for sets `A = {1, 2, 3}` and `B = {2, 3, 4}`, `A △ B = {1, 4}`.
Symmetric difference is a binary operation, which means it operates on only two elements. So to evaluate an expression involving symmetric differences among *three* elements (`A △ B △ C`), you must complete one operation at a time. Thus, for sets `A` and `B` above, and `C = {2, 3}`, `A △ B △ C = (A △ B) △ C = {1, 4} △ {2, 3} = {1, 2, 3, 4}`.
# --instructions--
Create a function that takes two or more arrays and returns an array of their symmetric difference. The returned array must contain only unique values (*no duplicates*).
# --hints--
`sym([1, 2, 3], [5, 2, 1, 4])`应返回`[3, 4, 5]`
`sym([1, 2, 3], [5, 2, 1, 4])` should return `[3, 4, 5]`.
```js
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5]);
```
`sym([1, 2, 3], [5, 2, 1, 4])`应仅包含三个元素。
`sym([1, 2, 3], [5, 2, 1, 4])` should contain only three elements.
```js
assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3);
```
`sym([1, 2, 3, 3], [5, 2, 1, 4])`应该返回`[3, 4, 5]`
`sym([1, 2, 3, 3], [5, 2, 1, 4])` should return `[3, 4, 5]`.
```js
assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5]);
```
`sym([1, 2, 3, 3], [5, 2, 1, 4])`应仅包含三个元素。
`sym([1, 2, 3, 3], [5, 2, 1, 4])` should contain only three elements.
```js
assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3);
```
`sym([1, 2, 3], [5, 2, 1, 4, 5])`应返回`[3, 4, 5]`
`sym([1, 2, 3], [5, 2, 1, 4, 5])` should return `[3, 4, 5]`.
```js
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5]);
```
`sym([1, 2, 3], [5, 2, 1, 4, 5])`应仅包含三个元素。
`sym([1, 2, 3], [5, 2, 1, 4, 5])` should contain only three elements.
```js
assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3);
```
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])`应该返回`[1, 4, 5]`
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` should return `[1, 4, 5]`
```js
assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5]);
```
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])`应仅包含三个元素。
`sym([1, 2, 5], [2, 3, 5], [3, 4, 5])` should contain only three elements.
```js
assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3);
```
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])`应该返回`[1, 4, 5]`
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` should return `[1, 4, 5]`.
```js
assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5]);
```
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])`应仅包含三个元素。
`sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])` should contain only three elements.
```js
assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3);
```
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])`应该返回`[2, 3, 4, 6, 7]` `sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` `[2, 3, 4, 6, 7]`
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` should return `[2, 3, 4, 6, 7]`.
```js
assert.sameMembers(
@ -81,7 +87,7 @@ assert.sameMembers(
);
```
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])`应仅包含五个元素。
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])` should contain only five elements.
```js
assert.equal(
@ -90,7 +96,7 @@ assert.equal(
);
```
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])`应该返回`[1, 2, 4, 5, 6, 7, 8, 9]`
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` should return `[1, 2, 4, 5, 6, 7, 8, 9]`.
```js
assert.sameMembers(
@ -106,7 +112,7 @@ assert.sameMembers(
);
```
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])`应该只包含八个元素。
`sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])` should contain only eight elements.
```js
assert.equal(

View File

@ -1,25 +1,30 @@
---
id: 8d5123c8c441eddfaeb5bdef
title: 实施冒泡排序
title: Implement Bubble Sort
challengeType: 1
videoUrl: ''
forumTopicId: 301612
dashedName: implement-bubble-sort
---
# --description--
这是排序算法的几个挑战中的第一个。给定一组未排序的项目,我们希望能够返回已排序的数组。我们将看到几种不同的方法来实现这一点,并学习这些不同方法之间的一些权衡。虽然大多数现代语言都有这样的操作的内置排序方法,但了解一些常见的基本方法并了解如何实现它们仍然很重要。在这里我们将看到冒泡排序。冒泡排序方法从未排序数组的开头开始,并向末端“冒泡”未排序的值,遍历数组直到它完全排序。它通过比较相邻的项目并在它们出现故障时交换它们来完成此操作。该方法继续循环遍历数组,直到没有发生交换,此时数组被排序。该方法需要通过阵列进行多次迭代,并且对于平均和最差情况,具有二次时间复杂度。虽然简单,但在大多数情况下通常都是不切实际的。 **说明:** 编写一个函数`bubbleSort` ,它将整数数组作为输入,并按从最小到最大的排序顺序返回这些整数的数组。 **注意:**
我们从幕后调用这个功能;我们使用的测试数组在编辑器中被注释掉了。尝试记录`array`以查看您的排序算法!
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.
# --hints--
`bubbleSort`是一个功能。
`bubbleSort` should be a function.
```js
assert(typeof bubbleSort == 'function');
```
`bubbleSort`返回一个已排序的数组(从最小到最大)。
`bubbleSort` should return a sorted array (least to greatest).
```js
assert(
@ -47,7 +52,7 @@ assert(
);
```
`bubbleSort`返回一个除订单外没有变化的数组。
`bubbleSort` should return an array that is unchanged except for order.
```js
assert.sameMembers(
@ -74,10 +79,10 @@ assert.sameMembers(
);
```
`bubbleSort`不应使用内置的`.sort()`方法。
`bubbleSort` should not use the built-in `.sort()` method.
```js
assert.strictEqual(code.search(/\.sort\(/), -1);
assert(isBuiltInSortUsed());
```
# --seed--

View File

@ -1,25 +1,26 @@
---
id: 587d8259367417b2b2512c86
title: 实现插入排序
title: Implement Insertion Sort
challengeType: 1
videoUrl: ''
forumTopicId: 301613
dashedName: implement-insertion-sort
---
# --description--
我们将看到的下一个排序方法是插入排序。此方法通过在列表的开头构建排序数组来工作。它以第一个元素开始排序数组。然后它检查下一个元素并将其向后交换到已排序的数组,直到它处于排序位置。它继续遍历列表并将新项目向后交换到已排序的部分,直到它到达结尾。该算法在平均和最差情况下具有二次时间复杂度。 **说明:** 编写一个函数`insertionSort` ,它将一个整数数组作为输入,并按照从最小到最大的排序顺序返回这些整数的数组。 **注意:**
我们从幕后调用这个功能;我们使用的测试数组在编辑器中被注释掉了。尝试记录`array`以查看您的排序算法!
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.
# --hints--
`insertionSort`是一个函数。
`insertionSort` should be a function.
```js
assert(typeof insertionSort == 'function');
```
`insertionSort`返回一个排序数组(从最小到最大)。
`insertionSort` should return a sorted array (least to greatest).
```js
assert(
@ -47,7 +48,7 @@ assert(
);
```
`insertionSort`返回一个除订单外没有变化的数组。
`insertionSort` should return an array that is unchanged except for order.
```js
assert.sameMembers(
@ -74,10 +75,10 @@ assert.sameMembers(
);
```
`insertionSort`不应使用内置的`.sort()`方法。
`insertionSort` should not use the built-in `.sort()` method.
```js
assert.strictEqual(code.search(/\.sort\(/), -1);
assert(isBuiltInSortUsed());
```
# --seed--

View File

@ -1,25 +1,34 @@
---
id: 587d825c367417b2b2512c8f
title: 实现合并排序
title: Implement Merge Sort
challengeType: 1
videoUrl: ''
forumTopicId: 301614
dashedName: implement-merge-sort
---
# --description--
另一种非常常见的中间排序算法是合并排序。像快速排序一样,合并排序也使用分而治之的递归方法对数组进行排序。它利用了这样一个事实:只要每个数组首先排序,就可以相对容易地对两个数组进行排序。但是我们只从一个数组作为输入开始,那么我们如何从中获得两个排序的数组呢?好吧,我们可以递归地将原始输入分成两部分,直到我们到达具有一个项目的数组的基本情况。单项数组是自然排序的,因此我们可以开始组合。这个组合将展开拆分原始数组的递归调用,最终生成所有元素的最终排序数组。然后,合并排序的步骤是: **1** 递归地将输入数组拆分为一半,直到产生仅具有一个元素的子数组。 **2将** 每个排序的子数组合并在一起以产生最终的排序数组。合并排序是一种有效的排序方法,时间复杂度为*Onlogn* 。该算法很受欢迎,因为它性能高且易于实现。顺便说一句,这将是我们在此处介绍的最后一种排序算法。但是,稍后在关于树数据结构的部分中,我们将描述堆排序,这是另一种在其实现中需要二进制堆的有效排序方法。 **说明:** 编写一个函数`mergeSort` ,它以整数数组作为输入,并按从最小到最大的排序顺序返回这些整数的数组。实现这一点的一个好方法是编写一个函数,例如`merge` ,它负责合并两个已排序的数组,另一个函数,例如`mergeSort` 它负责递归生成单项数组以提供给merge。祝你好运 **注意:**
我们从幕后调用这个功能;我们使用的测试数组在编辑器中被注释掉了。尝试记录`array`以查看您的排序算法!
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.
**2)** Merge each sorted sub-array together to produce the final sorted array.
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.
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!
# --hints--
`mergeSort`是一个函数。
`mergeSort` should be a function.
```js
assert(typeof mergeSort == 'function');
```
`mergeSort`返回一个排序数组(从最小到最大)。
`mergeSort` should return a sorted array (least to greatest).
```js
assert(
@ -47,7 +56,7 @@ assert(
);
```
`mergeSort`返回一个除订单外没有变化的数组。
`mergeSort` should return an array that is unchanged except for order.
```js
assert.sameMembers(
@ -74,10 +83,10 @@ assert.sameMembers(
);
```
`mergeSort`不应使用内置的`.sort()`方法。
`mergeSort` should not use the built-in `.sort()` method.
```js
assert.strictEqual(code.search(/\.sort\(/), -1);
assert(isBuiltInSortUsed());
```
# --seed--

View File

@ -1,25 +1,28 @@
---
id: 587d825a367417b2b2512c89
title: 实施快速排序
title: Implement Quick Sort
challengeType: 1
videoUrl: ''
forumTopicId: 301615
dashedName: implement-quick-sort
---
# --description--
在这里,我们将继续讨论中间排序算法:快速排序。快速排序是对数组进行排序的一种有效的,递归的分而治之的方法。在此方法中,在原始数组中选择了一个数据透视值。然后将该数组分成两个小于和大于数值的子数组。然后,我们在两个子阵列上结合递归调用快速排序算法的结果。这一直持续到达到空或单项数组的基本情况,我们返回。递归调用的展开将返回已排序的数组。快速排序是一种非常有效的排序方法,平均提供*Onlogn*性能。它也相对容易实现。这些属性使其成为一种流行且有用的排序方法。 **说明:** 编写一个函数`quickSort` ,它将整数数组作为输入,并按从最小到最大的排序顺序返回这些整数的数组。虽然枢轴值的选择很重要,但任何支点都可以用于我们的目的。为简单起见,可以使用第一个或最后一个元素。 **注意:**
我们从幕后调用这个功能;我们使用的测试数组在编辑器中被注释掉了。尝试记录`array`以查看您的排序算法!
Here we will move on to an intermediate sorting algorithm: quick sort. Quick sort is an efficient, recursive divide-and-conquer approach to sorting an array. In this method, a pivot value is chosen in the original array. The array is then partitioned into two subarrays of values less than and greater than the pivot value. We then combine the result of recursively calling the quick sort algorithm on both sub-arrays. This continues until the base case of an empty or single-item array is reached, which we return. The unwinding of the recursive calls return us the sorted array.
Quick sort is a very efficient sorting method, providing *O(nlog(n))* performance on average. It is also relatively easy to implement. These attributes make it a popular and useful sorting method.
**Instructions:** Write a function `quickSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. While the choice of the pivot value is important, any pivot will do for our purposes here. For simplicity, the first or last element could be used.
# --hints--
`quickSort`是一个功能。
`quickSort` should be a function.
```js
assert(typeof quickSort == 'function');
```
`quickSort`返回一个排序数组(从最小到最大)。
`quickSort` should return a sorted array (least to greatest).
```js
assert(
@ -47,7 +50,7 @@ assert(
);
```
`quickSort`返回一个除订单外没有变化的数组。
`quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` should return an array that is unchanged except for order.
```js
assert.sameMembers(
@ -74,10 +77,10 @@ assert.sameMembers(
);
```
`quickSort`不应使用内置的`.sort()`方法。
`quickSort` should not use the built-in `.sort()` method.
```js
assert.strictEqual(code.search(/\.sort\(/), -1);
assert(isBuiltInSortUsed());
```
# --seed--

View File

@ -1,25 +1,26 @@
---
id: 587d8259367417b2b2512c85
title: 实施选择排序
title: Implement Selection Sort
challengeType: 1
videoUrl: ''
forumTopicId: 301616
dashedName: implement-selection-sort
---
# --description--
这里我们将实现选择排序。选择排序的工作原理是选择列表中的最小值并使用列表中的第一个值进行交换。然后它从第二个位置开始,选择剩余列表中的最小值,并将其与第二个元素交换。它继续遍历列表并交换元素,直到它到达列表的末尾。现在列表已排序。在所有情况下,选择排序都具有二次时间复杂度。 **说明** :编写一个函数`selectionSort` ,它将一个整数数组作为输入,并按照从最小到最大的排序顺序返回这些整数的数组。 **注意:**
我们从幕后调用这个功能;我们使用的测试数组在编辑器中被注释掉了。尝试记录`array`以查看您的排序算法!
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.
# --hints--
`selectionSort`是一个函数。
`selectionSort` should be a function.
```js
assert(typeof selectionSort == 'function');
```
`selectionSort`返回一个排序数组(从最小到最大)。
`selectionSort` should return a sorted array (least to greatest).
```js
assert(
@ -47,7 +48,7 @@ assert(
);
```
`selectionSort`返回一个除订单外没有变化的数组。
`selectionSort` should return an array that is unchanged except for order.
```js
assert.sameMembers(
@ -74,10 +75,10 @@ assert.sameMembers(
);
```
`selectionSort`不应使用内置的`.sort()`方法。
`selectionSort` should not use the built-in `.sort()` method.
```js
assert.strictEqual(code.search(/\.sort\(/), -1);
assert(isBuiltInSortUsed());
```
# --seed--

View File

@ -1,18 +1,18 @@
---
id: a56138aff60341a09ed6c480
title: 库存更新
title: Inventory Update
challengeType: 5
videoUrl: ''
forumTopicId: 16019
dashedName: inventory-update
---
# --description--
比较并更新存储在2D阵列中的库存与新交付的第二个2D阵列。更新当前现有库存物料数量`arr1` )。如果找不到商品,请将新商品和数量添加到库存数组中。返回的库存数组应按项目的字母顺序排列。如果卡住,请记得使用[Read-Search-Ask](https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514) 。尝试配对程序。编写自己的代码。
Compare and update the inventory stored in a 2D array against a second 2D array of a fresh delivery. Update the current existing inventory item quantities (in `arr1`). If an item cannot be found, add the new item and quantity into the inventory array. The returned inventory array should be in alphabetical order by item.
# --hints--
函数`updateInventory`应该返回一个数组。
The function `updateInventory` should return an array.
```js
assert.isArray(
@ -33,7 +33,7 @@ assert.isArray(
);
```
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])`应该返回一个长度为6的数组。
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` should return an array with a length of 6.
```js
assert.equal(
@ -55,7 +55,7 @@ assert.equal(
);
```
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])`应返回`[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]`
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` should return `[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [3, "Half-Eaten Apple"], [5, "Microphone"], [7, "Toothpaste"]]`.
```js
assert.deepEqual(
@ -84,7 +84,7 @@ assert.deepEqual(
);
```
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])`应该返回`[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]`
`updateInventory([[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]], [])` should return `[[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]]`.
```js
assert.deepEqual(
@ -106,7 +106,7 @@ assert.deepEqual(
);
```
`updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])`应该返回`[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]`
`updateInventory([], [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]])` should return `[[67, "Bowling Ball"], [2, "Hair Pin"], [3, "Half-Eaten Apple"], [7, "Toothpaste"]]`.
```js
assert.deepEqual(
@ -128,7 +128,7 @@ assert.deepEqual(
);
```
`updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])`应返回`[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]`
`updateInventory([[0, "Bowling Ball"], [0, "Dirty Sock"], [0, "Hair Pin"], [0, "Microphone"]], [[1, "Hair Pin"], [1, "Half-Eaten Apple"], [1, "Bowling Ball"], [1, "Toothpaste"]])` should return `[[1, "Bowling Ball"], [0, "Dirty Sock"], [1, "Hair Pin"], [1, "Half-Eaten Apple"], [0, "Microphone"], [1, "Toothpaste"]]`.
```js
assert.deepEqual(

View File

@ -1,72 +1,74 @@
---
id: a7bf700cd123b9a54eef01d5
title: 请不要重复
title: No Repeats Please
challengeType: 5
videoUrl: ''
forumTopicId: 16037
dashedName: no-repeats-please
---
# --description--
返回没有重复连续字母的提供字符串的总排列数。假设提供的字符串中的所有字符都是唯一的。例如, `aab`应该返回2因为它总共有6个排列 `aab` `aab` `aba` `aba` `baa` `baa` 但只有2个 `aba``aba` )没有相同的字母(在这种情况下为`a` )重复。如果卡住,请记得使用[Read-Search-Ask](https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514) 。尝试配对程序。编写自己的代码。
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.
# --hints--
`permAlone("aab")`应返回一个数字。
`permAlone("aab")` should return a number.
```js
assert.isNumber(permAlone('aab'));
```
`permAlone("aab")`应返回2。
`permAlone("aab")` should return 2.
```js
assert.strictEqual(permAlone('aab'), 2);
```
`permAlone("aaa")`应该返回0。
`permAlone("aaa")` should return 0.
```js
assert.strictEqual(permAlone('aaa'), 0);
```
`permAlone("aabb")`应该返回8。
`permAlone("aabb")` should return 8.
```js
assert.strictEqual(permAlone('aabb'), 8);
```
`permAlone("abcdefa")`应返回3600
`permAlone("abcdefa")` should return 3600.
```js
assert.strictEqual(permAlone('abcdefa'), 3600);
```
`permAlone("abfdefa")`应返回2640
`permAlone("abfdefa")` should return 2640.
```js
assert.strictEqual(permAlone('abfdefa'), 2640);
```
`permAlone("zzzzzzzz")`应该返回0。
`permAlone("zzzzzzzz")` should return 0.
```js
assert.strictEqual(permAlone('zzzzzzzz'), 0);
```
`permAlone("a")`应返回1。
`permAlone("a")` should return 1.
```js
assert.strictEqual(permAlone('a'), 1);
```
`permAlone("aaab")`应该返回0。
`permAlone("aaab")` should return 0.
```js
assert.strictEqual(permAlone('aaab'), 0);
```
`permAlone("aaabb")`应该返回12
`permAlone("aaabb")` should return 12.
```js
assert.strictEqual(permAlone('aaabb'), 12);

View File

@ -1,50 +1,64 @@
---
id: a3f503de51cfab748ff001aa
title: 成对
title: Pairwise
challengeType: 5
videoUrl: ''
forumTopicId: 301617
dashedName: pairwise
---
# --description--
给定一个数组`arr` ,找到其总和等于第二个参数`arg`元素对,并返回它们的索引之和。您可以使用具有相同数字元素但索引不同的多个对。每对应使用尽可能低的可用指数。一旦元素被使用,它就不能被重用来与另一个元素配对。例如, `pairwise([1, 1, 2], 3)`使用indice 0处的1而不是indice 1处的1创建一对`[2, 1]` 因为0 + 2 &lt;1 + 2。例如 `pairwise([7, 9, 11, 13, 15], 20)`返回`6` 。总和为20的对是`[7, 13]``[9, 11]` 。然后我们可以用它们的索引和值写出数组。
Given an array `arr`, find element pairs whose sum equal the second argument `arg` and return the sum of their indices.
| **指数** | 0 | 1 | 2 | 3 | 4 |
| ------ | - | - | -- | -- | -- |
| 值 | 7 | 9 | 11 | 13 | 15 |
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 &lt; 1+2.
下面我们将采用相应的索引并添加它们。 7 + 13 = 20→指数0 + 3 = 3
9 + 11 = 20→指数1 + 2 = 3
3 + 3 = 6→返回`6`如果卡住,请记住使用[Read-Search-Ask](https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514) 。尝试配对程序。编写自己的代码。
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.
<div style='margin-left: 2em;'>
| Index | 0 | 1 | 2 | 3 | 4 |
| ----- | - | - | -- | -- | -- |
| Value | 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`
</div>
# --hints--
`pairwise([1, 4, 2, 3, 0, 5], 7)`应该返回11
`pairwise([1, 4, 2, 3, 0, 5], 7)` should return 11.
```js
assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11);
```
`pairwise([1, 3, 2, 4], 4)`应该返回1。
`pairwise([1, 3, 2, 4], 4)` should return 1.
```js
assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1);
```
`pairwise([1, 1, 1], 2)`应该返回1。
`pairwise([1, 1, 1], 2)` should return 1.
```js
assert.deepEqual(pairwise([1, 1, 1], 2), 1);
```
`pairwise([0, 0, 0, 0, 1, 1], 1)`应返回10
`pairwise([0, 0, 0, 0, 1, 1], 1)` should return 10.
```js
assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10);
```
`pairwise([], 100)`应该返回0。
`pairwise([], 100)` should return 0.
```js
assert.deepEqual(pairwise([], 100), 0);