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);

View File

@ -1,6 +1,6 @@
---
id: 587d8257367417b2b2512c7b
title: Add a New Element to a Binary Search Tree
title: 將新元素添加到二叉搜索樹
challengeType: 1
forumTopicId: 301618
dashedName: add-a-new-element-to-a-binary-search-tree
@ -8,27 +8,27 @@ dashedName: add-a-new-element-to-a-binary-search-tree
# --description--
This series of challenges will introduce the tree data structure. Trees are an important and versatile data structure in computer science. Of course, their name comes from the fact that when visualized they look much like the trees we are familiar with in the natural world. A tree data structure begins with one node, typically referred to as the root, and from here branches out to additional nodes, each of which may have more child nodes, and so on and so forth. The data structure is usually visualized with the root node at the top; you can think of it as a natural tree flipped upside down.
這一系列的挑戰將介紹樹形數據結構。 樹是計算機科學中一個重要的、通用的數據結構。 當然,它們的名稱來自這樣一個事實:當可視化時,它們看起來很像我們在自然界中熟悉的樹木。 樹數據結構從一個節點(通常稱爲根)開始,並從此處分支到其他節點,每個節點可能具有更多的子節點,依此類推。 數據結構通常以根節點爲頂點進行可視化;你可以把它想象成一棵倒過來的自然樹。
First, let's describe some common terminology we will encounter with trees. The root node is the top of the tree. Data points in the tree are called nodes. Nodes with branches leading to other nodes are referred to as the parent of the node the branch leads to (the child). Other more complicated familial terms apply as you might expect. A subtree refers to all the descendants of a particular node, branches may be referred to as edges, and leaf nodes are nodes at the end of the tree that have no children. Finally, note that trees are inherently recursive data structures. That is, any children of a node are parents of their own subtree, and so on. The recursive nature of trees is important to understand when designing algorithms for common tree operations.
首先,讓我們描述一下我們將遇到的關於樹的一些常見術語。 根節點root是樹的頂部。 樹中的數據點稱爲節點node。 分支通向其他節點的節點稱爲分支通向的節點(即子節點)的父節點。 如你所料,其他更復雜的家庭術語也適用。 子樹指的是某一特定節點的所有後代,分支可稱爲邊,而葉子節點是位於樹的末端的且沒有子節點的節點。 最後,請注意,樹本質上是遞歸的數據結構。 也就是說,一個節點的任何子節點都是其自己的子樹的父節點,依此類推。 在爲常見的樹操作設計算法時,樹的遞歸性質很重要。
To begin, we will discuss a particular type of a tree, the binary tree. In fact, we will actually discuss a particular binary tree, a binary search tree. Let's describe what this means. While the tree data structure can have any number of branches at a single node, a binary tree can only have two branches for every node. Furthermore, a binary search tree is ordered with respect to the child subtrees, such that the value of each node in the left subtree is less than or equal to the value of the parent node, and the value of each node in the right subtree is greater than or equal to the value of the parent node. It's very helpful to visualize this relationship in order to understand it better:
首先,我們將討論樹的一個特殊類型,即二叉樹。 實際上,我們將討論特定的二叉樹,即二叉搜索樹。 讓我們來看看這意味着什麼。 雖然樹形數據結構在一個節點上可以有任意數量的分支,但二叉樹每個節點只能有兩個分支。 此外,一個二叉搜索樹相對於其子子樹是有序的,即對於一個節點而言,其左子樹中每個節點的值都小於或等於該節點的值,而其右子樹中每個節點的值都大於或等於該節點的值。 爲了更好地理解這種關係,將這種關係形象化是非常有幫助的:
<div style='width: 100%; display: flex; justify-content: center; align-items: center;'><img style='width: 100%; max-width: 350px; background-color: var(--gray-05);' src='https://user-images.githubusercontent.com/18563015/32136009-1e665d98-bbd6-11e7-9133-63184f9f9182.png'></div>
Now this ordered relationship is very easy to see. Note that every value to the left of 8, the root node, is less than 8, and every value to the right is greater than 8. Also notice that this relationship applies to each of the subtrees as well. For example, the first left child is a subtree. 3 is the parent node, and it has exactly two child nodes — by the rules governing binary search trees, we know without even looking that the left child of this node (and any of its children) will be less than 3, and the right child (and any of its children) will be greater than 3 (but also less than the structure's root value), and so on.
現在,這種有序的關係是非常容易看到的。 注意,根節點 8 左邊的每個值都小於 8右邊的每個值都大於 8。 還要注意的是,這種關係也適用於每個子樹。 例如,第一個左孩子節點是一個子樹。 3 是父節點,它正好有兩個子節點——根據二進制搜索樹的規則,我們甚至不用看就知道這個節點的左子節點(以及它的任何子節點)都將小於 3右子節點以及它的任何子節點都將大於 3但也小於根結點的值依此類推。
Binary search trees are very common and useful data structures because they provide logarithmic time in the average case for several common operations such as lookup, insertion, and deletion.
二叉搜索樹是非常常見且有用的數據結構,因爲它們在幾種常見操作(例如查找、插入和刪除)的平均情況下提供對數的時間複雜度。
# --instructions--
We'll start simple. We've defined the skeleton of a binary search tree structure here in addition to a function to create nodes for our tree. Observe that each node may have a left and right value. These will be assigned child subtrees if they exist. In our binary search tree, you will create a method to add new values to our binary search tree. The method should be called `add` and it should accept an integer value to add to the tree. Take care to maintain the invariant of a binary search tree: the value in each left child should be less than or equal to the parent value, and the value in each right child should be greater than or equal to the parent value. Here, let's make it so our tree cannot hold duplicate values. If we try to add a value that already exists, the method should return `null`. Otherwise, if the addition is successful, `undefined` should be returned.
我們將從簡單的內容開始。 我們在這裏定義了一個二叉搜索樹結構的骨架,此外還有一個爲我們的樹創建節點的函數。 注意觀察每個節點可能有一個左值和右值。 如果子樹存在,它們將被分配給對應的子樹。 在我們的二叉搜索樹中,你將創建一個方法來向我們的二叉搜索樹添加新的值。 該方法應該被稱爲`add` ,它應該接受一個整數值來添加到樹中。 注意保持二叉搜索樹的不變量:每個左子項中的值應小於或等於父值,並且每個右子項中的值應大於或等於父值。 在這裏,讓我們確保我們的樹不會含有重複的值。 如果我們嘗試添加已存在的值,則該方法應返回`null` 。 否則,如果添加成功,則應返回`undefined`
**Hint:** trees are naturally recursive data structures!
**提示:** 樹是自然的遞歸數據結構!
# --hints--
The `BinarySearchTree` data structure should exist.
存在 `BinarySearchTree` 的數據結構。
```js
assert(
@ -42,7 +42,7 @@ assert(
);
```
The binary search tree should have a method called `add`.
二叉搜索樹應該有一個名爲 `add` 的方法。
```js
assert(
@ -58,7 +58,7 @@ assert(
);
```
The add method should add elements according to the binary search tree rules.
添加的方法應該根據二叉搜索樹的規則來添加元素。
```js
assert(
@ -87,7 +87,7 @@ assert(
);
```
Adding an element that already exists should return `null`.
添加一個已經存在的元素應該返回 `null`
```js
assert(