chore(i8n,learn): processed translations (#41462)
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: acda2fb1324d9b0fa741e6b5
|
id: acda2fb1324d9b0fa741e6b5
|
||||||
title: Confirm the Ending
|
title: 确认结尾
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16006
|
forumTopicId: 16006
|
||||||
dashedName: confirm-the-ending
|
dashedName: confirm-the-ending
|
||||||
@ -8,31 +8,31 @@ dashedName: confirm-the-ending
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Check if a string (first argument, `str`) ends with the given target string (second argument, `target`).
|
检查字符串(第一个参数 `str`)是否以给定的目标字符串(第二个参数 `target`)结束。
|
||||||
|
|
||||||
This challenge *can* be solved with the `.endsWith()` method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.
|
这个挑战 *可以* 用 ES2015 引入的 `.endsWith()` 方法来解决。但在这个挑战中,请使用 JavaScript 的字符串子串方法。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`confirmEnding("Bastian", "n")` should return true.
|
`confirmEnding("Bastian", "n")` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('Bastian', 'n') === true);
|
assert(confirmEnding('Bastian', 'n') === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("Congratulation", "on")` should return true.
|
`confirmEnding("Congratulation", "on")` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('Congratulation', 'on') === true);
|
assert(confirmEnding('Congratulation', 'on') === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("Connor", "n")` should return false.
|
`confirmEnding("Connor", "n")` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('Connor', 'n') === false);
|
assert(confirmEnding('Connor', 'n') === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")` should return false.
|
`confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -43,31 +43,31 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("He has to give me a new name", "name")` should return true.
|
`confirmEnding("He has to give me a new name", "name")` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('He has to give me a new name', 'name') === true);
|
assert(confirmEnding('He has to give me a new name', 'name') === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("Open sesame", "same")` should return true.
|
`confirmEnding("Open sesame", "same")` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('Open sesame', 'same') === true);
|
assert(confirmEnding('Open sesame', 'same') === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("Open sesame", "sage")` should return false.
|
`confirmEnding("Open sesame", "sage")` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('Open sesame', 'sage') === false);
|
assert(confirmEnding('Open sesame', 'sage') === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("Open sesame", "game")` should return false.
|
`confirmEnding("Open sesame", "game")` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('Open sesame', 'game') === false);
|
assert(confirmEnding('Open sesame', 'game') === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")` should return false.
|
`confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -78,13 +78,13 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`confirmEnding("Abstraction", "action")` should return true.
|
`confirmEnding("Abstraction", "action")` 应该返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(confirmEnding('Abstraction', 'action') === true);
|
assert(confirmEnding('Abstraction', 'action') === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
Your code should not use the built-in method `.endsWith()` to solve the challenge.
|
不应使用内置方法 `.endsWith()` 来完成挑战。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!/\.endsWith\(.*?\)\s*?;?/.test(code) && !/\['endsWith'\]/.test(code));
|
assert(!/\.endsWith\(.*?\)\s*?;?/.test(code) && !/\['endsWith'\]/.test(code));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: a302f7aae1aa3152a5b413bc
|
id: a302f7aae1aa3152a5b413bc
|
||||||
title: Factorialize a Number
|
title: 计算整数的阶乘
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16013
|
forumTopicId: 16013
|
||||||
dashedName: factorialize-a-number
|
dashedName: factorialize-a-number
|
||||||
@ -8,43 +8,43 @@ dashedName: factorialize-a-number
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Return the factorial of the provided integer.
|
返回一个给定整数的阶乘计算结果。
|
||||||
|
|
||||||
If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.
|
对于整数 `n`,n 的阶乘就是所有小于等于 `n` 的正整数的乘积。
|
||||||
|
|
||||||
Factorials are often represented with the shorthand notation `n!`
|
阶乘通常用符号 `n!` 来表示。
|
||||||
|
|
||||||
For example: `5! = 1 * 2 * 3 * 4 * 5 = 120`
|
例如:`5! = 1 * 2 * 3 * 4 * 5 = 120`
|
||||||
|
|
||||||
Only integers greater than or equal to zero will be supplied to the function.
|
在这个挑战中,只有非负整数会作为参数传入函数。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`factorialize(5)` should return a number.
|
`factorialize(5)` 应返回一个数字。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(typeof factorialize(5) === 'number');
|
assert(typeof factorialize(5) === 'number');
|
||||||
```
|
```
|
||||||
|
|
||||||
`factorialize(5)` should return 120.
|
`factorialize(5)` 应该返回 `120`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(factorialize(5) === 120);
|
assert(factorialize(5) === 120);
|
||||||
```
|
```
|
||||||
|
|
||||||
`factorialize(10)` should return 3628800.
|
`factorialize(10)` 应该返回 `3628800`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(factorialize(10) === 3628800);
|
assert(factorialize(10) === 3628800);
|
||||||
```
|
```
|
||||||
|
|
||||||
`factorialize(20)` should return 2432902008176640000.
|
`factorialize(20)` 应该返回 `2432902008176640000`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(factorialize(20) === 2432902008176640000);
|
assert(factorialize(20) === 2432902008176640000);
|
||||||
```
|
```
|
||||||
|
|
||||||
`factorialize(0)` should return 1.
|
`factorialize(0)` 应该返回 `1`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(factorialize(0) === 1);
|
assert(factorialize(0) === 1);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: a26cbbe9ad8655a977e1ceb5
|
id: a26cbbe9ad8655a977e1ceb5
|
||||||
title: Find the Longest Word in a String
|
title: 找出字符串中的最长单词
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16015
|
forumTopicId: 16015
|
||||||
dashedName: find-the-longest-word-in-a-string
|
dashedName: find-the-longest-word-in-a-string
|
||||||
@ -8,13 +8,13 @@ dashedName: find-the-longest-word-in-a-string
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Return the length of the longest word in the provided sentence.
|
返回给出的句子中,最长单词的长度。
|
||||||
|
|
||||||
Your response should be a number.
|
函数的返回值应是一个数字。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`findLongestWordLength("The quick brown fox jumped over the lazy dog")` should return a number.
|
`findLongestWordLength("The quick brown fox jumped over the lazy dog")` 应返回一个数字。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -24,7 +24,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`findLongestWordLength("The quick brown fox jumped over the lazy dog")` should return 6.
|
`findLongestWordLength("The quick brown fox jumped over the lazy dog")` 应返回 `6`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -32,19 +32,19 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`findLongestWordLength("May the force be with you")` should return 5.
|
`findLongestWordLength("May the force be with you")` 应返回 `5`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(findLongestWordLength('May the force be with you') === 5);
|
assert(findLongestWordLength('May the force be with you') === 5);
|
||||||
```
|
```
|
||||||
|
|
||||||
`findLongestWordLength("Google do a barrel roll")` should return 6.
|
`findLongestWordLength("Google do a barrel roll")` 应返回 `6`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(findLongestWordLength('Google do a barrel roll') === 6);
|
assert(findLongestWordLength('Google do a barrel roll') === 6);
|
||||||
```
|
```
|
||||||
|
|
||||||
`findLongestWordLength("What is the average airspeed velocity of an unladen swallow")` should return 8.
|
`findLongestWordLength("What is the average airspeed velocity of an unladen swallow")` 应返回 `8`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -54,7 +54,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")` should return 19.
|
`findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")` 应返回 `19`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: a6e40f1041b06c996f7b2406
|
id: a6e40f1041b06c996f7b2406
|
||||||
title: Finders Keepers
|
title: 按参数过滤数组
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16016
|
forumTopicId: 16016
|
||||||
dashedName: finders-keepers
|
dashedName: finders-keepers
|
||||||
@ -8,11 +8,11 @@ dashedName: finders-keepers
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Create a function that looks through an array `arr` and returns the first element in it that passes a 'truth test'. This means that given an element `x`, the 'truth test' is passed if `func(x)` is `true`. If no element passes the test, return `undefined`.
|
请写一个函数来检查数组(第一个参数 `arr`)中的元素,并返回数组中第一个通过校验测试的元素。 其中,“通过校验测试”指的是对于数组中的一个元素 `x`,若 `func(x)` 返回的结果为 `true`,则校验测试通过。 如果没有元素通过测试,请返回 `undefined`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; })` should return 8.
|
`findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; })` 应返回 `8`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
@ -23,7 +23,7 @@ assert.strictEqual(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })` should return undefined.
|
`findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })` 应返回 `undefined`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: af2170cad53daa0770fabdea
|
id: af2170cad53daa0770fabdea
|
||||||
title: Mutations
|
title: 比较字符串
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16025
|
forumTopicId: 16025
|
||||||
dashedName: mutations
|
dashedName: mutations
|
||||||
@ -8,83 +8,83 @@ dashedName: mutations
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
|
如果数组里的第一个字符串包含了第二个字符串中的所有字母,则返回 `true`。
|
||||||
|
|
||||||
For example, `["hello", "Hello"]`, should return true because all of the letters in the second string are present in the first, ignoring case.
|
例如,`["hello", "Hello"]` 应该返回 `true`。因为在忽略大小写的情况下,第一个字符串包含了第二个字符串里出现的所有字母。
|
||||||
|
|
||||||
The arguments `["hello", "hey"]` should return false because the string "hello" does not contain a "y".
|
`["hello", "hey"]` 应该返回 `false`。因为 `hello` 并不包含字符 `y`。
|
||||||
|
|
||||||
Lastly, `["Alien", "line"]`, should return true because all of the letters in "line" are present in "Alien".
|
最后,`["Alien", "line"]` 应该返回 `true`。因为 `line` 中的所有字母都出现在了 `Alien` 中。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`mutation(["hello", "hey"])` should return false.
|
`mutation(["hello", "hey"])` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['hello', 'hey']) === false);
|
assert(mutation(['hello', 'hey']) === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["hello", "Hello"])` should return true.
|
`mutation(["hello", "Hello"])` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['hello', 'Hello']) === true);
|
assert(mutation(['hello', 'Hello']) === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])` should return true.
|
`mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu']) === true);
|
assert(mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu']) === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["Mary", "Army"])` should return true.
|
`mutation(["Mary", "Army"])` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['Mary', 'Army']) === true);
|
assert(mutation(['Mary', 'Army']) === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["Mary", "Aarmy"])` should return true.
|
`mutation(["Mary", "Aarmy"])` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['Mary', 'Aarmy']) === true);
|
assert(mutation(['Mary', 'Aarmy']) === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["Alien", "line"])` should return true.
|
`mutation(["Alien", "line"])` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['Alien', 'line']) === true);
|
assert(mutation(['Alien', 'line']) === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["floor", "for"])` should return true.
|
`mutation(["floor", "for"])` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['floor', 'for']) === true);
|
assert(mutation(['floor', 'for']) === true);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["hello", "neo"])` should return false.
|
`mutation(["hello", "neo"])` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['hello', 'neo']) === false);
|
assert(mutation(['hello', 'neo']) === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["voodoo", "no"])` should return false.
|
`mutation(["voodoo", "no"])` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['voodoo', 'no']) === false);
|
assert(mutation(['voodoo', 'no']) === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["ate", "date"]` should return false.
|
`mutation(["ate", "date"])` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['ate', 'date']) === false);
|
assert(mutation(['ate', 'date']) === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["Tiger", "Zebra"])` should return false.
|
`mutation(["Tiger", "Zebra"])` 应返回 `false`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['Tiger', 'Zebra']) === false);
|
assert(mutation(['Tiger', 'Zebra']) === false);
|
||||||
```
|
```
|
||||||
|
|
||||||
`mutation(["Noel", "Ole"])` should return true.
|
`mutation(["Noel", "Ole"])` 应返回 `true`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mutation(['Noel', 'Ole']) === true);
|
assert(mutation(['Noel', 'Ole']) === true);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: afcc8d540bea9ea2669306b6
|
id: afcc8d540bea9ea2669306b6
|
||||||
title: Repeat a String Repeat a String
|
title: 重复输出字符串
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16041
|
forumTopicId: 16041
|
||||||
dashedName: repeat-a-string-repeat-a-string
|
dashedName: repeat-a-string-repeat-a-string
|
||||||
@ -8,53 +8,53 @@ dashedName: repeat-a-string-repeat-a-string
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Repeat a given string `str` (first argument) for `num` times (second argument). Return an empty string if `num` is not a positive number. For the purpose of this challenge, do *not* use the built-in `.repeat()` method.
|
将一个给定的字符串 `str`(第一个参数)重复输出 `num`(第二个参数)次。 如果 `num` 不是正数,返回空字符串。 在这个挑战中,请*不要*使用 JavaScript 内置的 `.repeat()` 方法。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`repeatStringNumTimes("*", 3)` should return `"***"`.
|
`repeatStringNumTimes("*", 3)` 应返回 `***`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(repeatStringNumTimes('*', 3) === '***');
|
assert(repeatStringNumTimes('*', 3) === '***');
|
||||||
```
|
```
|
||||||
|
|
||||||
`repeatStringNumTimes("abc", 3)` should return `"abcabcabc"`.
|
`repeatStringNumTimes("abc", 3)` 应返回 `abcabcabc`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(repeatStringNumTimes('abc', 3) === 'abcabcabc');
|
assert(repeatStringNumTimes('abc', 3) === 'abcabcabc');
|
||||||
```
|
```
|
||||||
|
|
||||||
`repeatStringNumTimes("abc", 4)` should return `"abcabcabcabc"`.
|
`repeatStringNumTimes("abc", 4)` 应返回 `abcabcabcabc`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(repeatStringNumTimes('abc', 4) === 'abcabcabcabc');
|
assert(repeatStringNumTimes('abc', 4) === 'abcabcabcabc');
|
||||||
```
|
```
|
||||||
|
|
||||||
`repeatStringNumTimes("abc", 1)` should return `"abc"`.
|
`repeatStringNumTimes("abc", 1)` 应返回 `abc`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(repeatStringNumTimes('abc', 1) === 'abc');
|
assert(repeatStringNumTimes('abc', 1) === 'abc');
|
||||||
```
|
```
|
||||||
|
|
||||||
`repeatStringNumTimes("*", 8)` should return `"********"`.
|
`repeatStringNumTimes("*", 8)` 应返回 `********`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(repeatStringNumTimes('*', 8) === '********');
|
assert(repeatStringNumTimes('*', 8) === '********');
|
||||||
```
|
```
|
||||||
|
|
||||||
`repeatStringNumTimes("abc", -2)` should return `""`.
|
`repeatStringNumTimes("abc", -2)` 应返回 `""`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(repeatStringNumTimes('abc', -2) === '');
|
assert(repeatStringNumTimes('abc', -2) === '');
|
||||||
```
|
```
|
||||||
|
|
||||||
The built-in `repeat()` method should not be used.
|
不应使用内置的 `repeat()` 方法。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!/\.repeat/g.test(code));
|
assert(!/\.repeat/g.test(code));
|
||||||
```
|
```
|
||||||
|
|
||||||
`repeatStringNumTimes("abc", 0)` should return `""`.
|
`repeatStringNumTimes("abc", 0)` 应返回 `""`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(repeatStringNumTimes('abc', 0) === '');
|
assert(repeatStringNumTimes('abc', 0) === '');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: a202eed8fc186c8434cb6d61
|
id: a202eed8fc186c8434cb6d61
|
||||||
title: Reverse a String
|
title: 反转字符串
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16043
|
forumTopicId: 16043
|
||||||
dashedName: reverse-a-string
|
dashedName: reverse-a-string
|
||||||
@ -8,33 +8,33 @@ dashedName: reverse-a-string
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Reverse the provided string.
|
请反转传入函数的字符串。
|
||||||
|
|
||||||
You may need to turn the string into an array before you can reverse it.
|
在反转字符串之前,你可能需要将其切分成包含字符的数组。
|
||||||
|
|
||||||
Your result must be a string.
|
函数的返回结果应为字符串。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`reverseString("hello")` should return a string.
|
`reverseString("hello")` 应返回一个字符串。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(typeof reverseString('hello') === 'string');
|
assert(typeof reverseString('hello') === 'string');
|
||||||
```
|
```
|
||||||
|
|
||||||
`reverseString("hello")` should become `"olleh"`.
|
`reverseString("hello")` 应返回 `olleh`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(reverseString('hello') === 'olleh');
|
assert(reverseString('hello') === 'olleh');
|
||||||
```
|
```
|
||||||
|
|
||||||
`reverseString("Howdy")` should become `"ydwoH"`.
|
`reverseString("Howdy")` 应返回 `ydwoH`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(reverseString('Howdy') === 'ydwoH');
|
assert(reverseString('Howdy') === 'ydwoH');
|
||||||
```
|
```
|
||||||
|
|
||||||
`reverseString("Greetings from Earth")` should return `"htraE morf sgniteerG"`.
|
`reverseString("Greetings from Earth")` 应返回 `htraE morf sgniteerG`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(reverseString('Greetings from Earth') === 'htraE morf sgniteerG');
|
assert(reverseString('Greetings from Earth') === 'htraE morf sgniteerG');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: ab6137d4e35944e21037b769
|
id: ab6137d4e35944e21037b769
|
||||||
title: Title Case a Sentence
|
title: 句中单词首字母大写
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16088
|
forumTopicId: 16088
|
||||||
dashedName: title-case-a-sentence
|
dashedName: title-case-a-sentence
|
||||||
@ -8,31 +8,31 @@ dashedName: title-case-a-sentence
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
|
请将传入的字符串中,每个单词的第一个字母变成大写并返回。 注意除首字母外,其余的字符都应是小写的。
|
||||||
|
|
||||||
For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".
|
在这个挑战中,我们还需要将诸如 `the` 和 `of` 之类的连接词大写。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`titleCase("I'm a little tea pot")` should return a string.
|
`titleCase("I'm a little tea pot")` 应返回一个字符串。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(typeof titleCase("I'm a little tea pot") === 'string');
|
assert(typeof titleCase("I'm a little tea pot") === 'string');
|
||||||
```
|
```
|
||||||
|
|
||||||
`titleCase("I'm a little tea pot")` should return `I'm A Little Tea Pot`.
|
`titleCase("I'm a little tea pot")` 应返回 `I'm A Little Tea Pot`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot");
|
assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot");
|
||||||
```
|
```
|
||||||
|
|
||||||
`titleCase("sHoRt AnD sToUt")` should return `Short And Stout`.
|
`titleCase("sHoRt AnD sToUt")` 应返回 `Short And Stout`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(titleCase('sHoRt AnD sToUt') === 'Short And Stout');
|
assert(titleCase('sHoRt AnD sToUt') === 'Short And Stout');
|
||||||
```
|
```
|
||||||
|
|
||||||
`titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")` should return `Here Is My Handle Here Is My Spout`.
|
`titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")` 应返回 `Here Is My Handle Here Is My Spout`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: ac6993d51946422351508a41
|
id: ac6993d51946422351508a41
|
||||||
title: Truncate a String
|
title: 截断字符串
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
forumTopicId: 16089
|
forumTopicId: 16089
|
||||||
dashedName: truncate-a-string
|
dashedName: truncate-a-string
|
||||||
@ -8,11 +8,11 @@ dashedName: truncate-a-string
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a `...` ending.
|
如果传入的字符串(第一个参数)的长度大于传入的值(第二个参数),请在这个位置截断它, 并在后面加上 `...`,然后返回结果。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`truncateString("A-tisket a-tasket A green and yellow basket", 8)` should return "A-tisket...".
|
`truncateString("A-tisket a-tasket A green and yellow basket", 8)` 应返回 `A-tisket...`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -21,7 +21,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`truncateString("Peter Piper picked a peck of pickled peppers", 11)` should return "Peter Piper...".
|
`truncateString("Peter Piper picked a peck of pickled peppers", 11)` 应返回 `Peter Piper...`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -30,7 +30,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)` should return "A-tisket a-tasket A green and yellow basket".
|
`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)` 应返回 `A-tisket a-tasket A green and yellow basket`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -41,7 +41,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)` should return "A-tisket a-tasket A green and yellow basket".
|
`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)` 应返回 `A-tisket a-tasket A green and yellow basket`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -52,13 +52,13 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`truncateString("A-", 1)` should return "A...".
|
`truncateString("A-", 1)` 应返回字符串 `A...`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(truncateString('A-', 1) === 'A...');
|
assert(truncateString('A-', 1) === 'A...');
|
||||||
```
|
```
|
||||||
|
|
||||||
`truncateString("Absolutely Longer", 2)` should return "Ab...".
|
`truncateString("Absolutely Longer", 2)` 应返回 `Ab...`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(truncateString('Absolutely Longer', 2) === 'Ab...');
|
assert(truncateString('Absolutely Longer', 2) === 'Ab...');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 5a661e0f1068aca922b3ef17
|
id: 5a661e0f1068aca922b3ef17
|
||||||
title: Access an Array's Contents Using Bracket Notation
|
title: 使用方括号访问数组的元素
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
forumTopicId: 301149
|
forumTopicId: 301149
|
||||||
dashedName: access-an-arrays-contents-using-bracket-notation
|
dashedName: access-an-arrays-contents-using-bracket-notation
|
||||||
@ -8,55 +8,55 @@ dashedName: access-an-arrays-contents-using-bracket-notation
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
The fundamental feature of any data structure is, of course, the ability to not only store data, but to be able to retrieve that data on command. So, now that we've learned how to create an array, let's begin to think about how we can access that array's information.
|
所有数据结构的基本特性是,它们不仅可以存储数据,还可以让我们按需访问存放在其中的数据。 我们已经学习了如何创建数组,现在让我们来学习如何访问数组中的数据。
|
||||||
|
|
||||||
When we define a simple array as seen below, there are 3 items in it:
|
我们先定义一个包含 3 个元素的数组:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
let ourArray = ["a", "b", "c"];
|
let ourArray = ["a", "b", "c"];
|
||||||
```
|
```
|
||||||
|
|
||||||
In an array, each array item has an <dfn>index</dfn>. This index doubles as the position of that item in the array, and how you reference it. However, it is important to note, that JavaScript arrays are <dfn>zero-indexed</dfn>, meaning that the first element of an array is actually at the ***zeroth*** position, not the first. In order to retrieve an element from an array we can enclose an index in brackets and append it to the end of an array, or more commonly, to a variable which references an array object. This is known as <dfn>bracket notation</dfn>. For example, if we want to retrieve the `"a"` from `ourArray` and assign it to a variable, we can do so with the following code:
|
在数组中,内部的每个元素都有一个与之对应的索引(<dfn>index</dfn>)。 索引既是该元素在数组中的位置,也是我们访问该元素的引用。 需要注意的是,JavaScript 数组的索引是从 0 开始的(这种从 0 开始的规则叫做 <dfn>zero-indexed</dfn>),即数组的第一个元素是在数组中的***第 0 个***位置,而不是第 1 个位置。 要从数组中获取一个元素,我们可以在数组字面量后面加一个用方括号括起来的索引。不过习惯上,我们会通过表示数组的变量名来访问,而不是直接通过字面量。 这种从数组中读取元素的方式叫做方括号表示法(<dfn>bracket notation</dfn>)。 如果我们要从数组 `ourArray` 中取出数据 `a` 并将其赋值给另一个变量,可以这样写:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
let ourVariable = ourArray[0];
|
let ourVariable = ourArray[0];
|
||||||
// ourVariable equals "a"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
In addition to accessing the value associated with an index, you can also *set* an index to a value using the same notation:
|
现在,变量 `ourVariable` 的值也为 `a`。
|
||||||
|
|
||||||
|
通过索引,我们不仅可以获取某个元素值,还可以用类似的写法来*设置*一个索引位置的元素值:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
ourArray[1] = "not b anymore";
|
ourArray[1] = "not b anymore";
|
||||||
// ourArray now equals ["a", "not b anymore", "c"];
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Using bracket notation, we have now reset the item at index 1 from `"b"`, to `"not b anymore"`.
|
在上面的代码中,我们用方括号表示法把索引为 1 的元素从 `b` 改成了 `not b anymore`。 现在 `ourArray` 的值是 `["a", "not b anymore", "c"]`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
In order to complete this challenge, set the 2nd position (index `1`) of `myArray` to anything you want, besides `"b"`.
|
在本挑战中,请将 `myArray` 中的第二个元素(索引为 `1`)设置为除了 `b` 以外的任意值。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`myArray[0]` should be equal to `"a"`
|
`myArray[0]` 应为 `a`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(myArray[0], 'a');
|
assert.strictEqual(myArray[0], 'a');
|
||||||
```
|
```
|
||||||
|
|
||||||
`myArray[1]` should not be equal to `"b"`
|
`myArray[1]` 不应为 `b`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.notStrictEqual(myArray[1], 'b');
|
assert.notStrictEqual(myArray[1], 'b');
|
||||||
```
|
```
|
||||||
|
|
||||||
`myArray[2]` should be equal to `"c"`
|
`myArray[2]` 应为 `c`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(myArray[2], 'c');
|
assert.strictEqual(myArray[2], 'c');
|
||||||
```
|
```
|
||||||
|
|
||||||
`myArray[3]` should be equal to `"d"`
|
`myArray[3]` 应为 `d`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(myArray[3], 'd');
|
assert.strictEqual(myArray[3], 'd');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 587d78b2367417b2b2512b0e
|
id: 587d78b2367417b2b2512b0e
|
||||||
title: Add Items to an Array with push() and unshift()
|
title: 使用 push() 和 unshift() 为数组添加元素
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
forumTopicId: 301151
|
forumTopicId: 301151
|
||||||
dashedName: add-items-to-an-array-with-push-and-unshift
|
dashedName: add-items-to-an-array-with-push-and-unshift
|
||||||
@ -8,28 +8,32 @@ dashedName: add-items-to-an-array-with-push-and-unshift
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
An array's length, like the data types it can contain, is not fixed. Arrays can be defined with a length of any number of elements, and elements can be added or removed over time; in other words, arrays are <dfn>mutable</dfn>. In this challenge, we will look at two methods with which we can programmatically modify an array: `Array.push()` and `Array.unshift()`.
|
数组的长度与数组能包含的数据类型一样,都是不固定的。 数组可以包含任意数量的元素,可以不限次数地往数组中添加元素或者从中移除元素。 总之,数组是可变的(<dfn>mutable</dfn>)。 在本挑战中,我们要学习两种修改数组的方法:`Array.push()` 和 `Array.unshift()`。
|
||||||
|
|
||||||
Both methods take one or more elements as parameters and add those elements to the array the method is being called on; the `push()` method adds elements to the end of an array, and `unshift()` adds elements to the beginning. Consider the following:
|
这两个方法都接收一个或多个元素作为参数,并会将参数中的元素添加到该数组中。 `push()` 方法会将元素插入到数组的末尾,而 `unshift()` 方法会将元素插入到数组的开头。 请看以下例子:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
let twentyThree = 'XXIII';
|
let twentyThree = 'XXIII';
|
||||||
let romanNumerals = ['XXI', 'XXII'];
|
let romanNumerals = ['XXI', 'XXII'];
|
||||||
|
|
||||||
romanNumerals.unshift('XIX', 'XX');
|
romanNumerals.unshift('XIX', 'XX');
|
||||||
// now equals ['XIX', 'XX', 'XXI', 'XXII']
|
|
||||||
|
|
||||||
romanNumerals.push(twentyThree);
|
|
||||||
// now equals ['XIX', 'XX', 'XXI', 'XXII', 'XXIII']Notice that we can also pass variables, which allows us even greater flexibility in dynamically modifying our array's data.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`romanNumerals` 的值就变成了 `['XIX', 'XX', 'XXI', 'XXII']`。
|
||||||
|
|
||||||
|
```js
|
||||||
|
romanNumerals.push(twentyThree);
|
||||||
|
```
|
||||||
|
|
||||||
|
`romanNumerals` 的值现在就变成了 `['XIX', 'XX', 'XXI', 'XXII', 'XXIII']`。 请注意这里,我们也可以使用变量作为参数,这让我们在动态修改数组数据时更加灵活。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
We have defined a function, `mixedNumbers`, which we are passing an array as an argument. Modify the function by using `push()` and `unshift()` to add `'I', 2, 'three'` to the beginning of the array and `7, 'VIII', 9` to the end so that the returned array contains representations of the numbers 1-9 in order.
|
我们已经定义了一个 `mixedNumbers` 函数,它接收一个数组作为参数。 请修改这个函数,使用 `push()` 和 `unshift()` 来将 `'I', 2, 'three'` 插入到数组开头;将 `7, 'VIII', 9` 插入到数组的末尾。最终这个函数的返回值就会是一个依次包含不同形式的 1-9 的数组。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`mixedNumbers(["IV", 5, "six"])` should now return `["I", 2, "three", "IV", 5, "six", 7, "VIII", 9]`
|
`mixedNumbers(["IV", 5, "six"])` 应返回 `["I", 2, "three", "IV", 5, "six", 7, "VIII", 9]`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.deepEqual(mixedNumbers(['IV', 5, 'six']), [
|
assert.deepEqual(mixedNumbers(['IV', 5, 'six']), [
|
||||||
@ -45,13 +49,13 @@ assert.deepEqual(mixedNumbers(['IV', 5, 'six']), [
|
|||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
|
|
||||||
The `mixedNumbers` function should utilize the `push()` method
|
`mixedNumbers` 函数中应调用 `push()` 方法。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mixedNumbers.toString().match(/\.push/));
|
assert(mixedNumbers.toString().match(/\.push/));
|
||||||
```
|
```
|
||||||
|
|
||||||
The `mixedNumbers` function should utilize the `unshift()` method
|
`mixedNumbers` 函数中应调用 `unshift()` 方法。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(mixedNumbers.toString().match(/\.unshift/));
|
assert(mixedNumbers.toString().match(/\.unshift/));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 56533eb9ac21ba0edf2244d4
|
id: 56533eb9ac21ba0edf2244d4
|
||||||
title: Comparison with the Greater Than Operator
|
title: 大于运算符
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
videoUrl: 'https://scrimba.com/c/cp6GbH4'
|
videoUrl: 'https://scrimba.com/c/cp6GbH4'
|
||||||
forumTopicId: 16786
|
forumTopicId: 16786
|
||||||
@ -9,68 +9,70 @@ dashedName: comparison-with-the-greater-than-operator
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
The greater than operator (`>`) compares the values of two numbers. If the number to the left is greater than the number to the right, it returns `true`. Otherwise, it returns `false`.
|
使用大于运算符(`>`)来比较两个数字。 如果大于运算符左边的数字大于右边的数字,将会返回 `true`。 否则,它返回 `false`。
|
||||||
|
|
||||||
Like the equality operator, greater than operator will convert data types of values while comparing.
|
与相等运算符一样,大于运算符在比较的时候,会转换值的数据类型。
|
||||||
|
|
||||||
**Examples**
|
**例如:**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
5 > 3 // true
|
5 > 3
|
||||||
7 > '3' // true
|
7 > '3'
|
||||||
2 > 3 // false
|
2 > 3
|
||||||
'1' > 9 // false
|
'1' > 9
|
||||||
```
|
```
|
||||||
|
|
||||||
|
按顺序,这些表达式会返回 `true`、`true`、`false` 和 `false`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Add the greater than operator to the indicated lines so that the return statements make sense.
|
添加大于运算符到指定的行,使得返回的语句是有意义的。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`testGreaterThan(0)` should return "10 or Under"
|
`testGreaterThan(0)` 应该返回字符串 `10 or Under`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testGreaterThan(0) === '10 or Under');
|
assert(testGreaterThan(0) === '10 or Under');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testGreaterThan(10)` should return "10 or Under"
|
`testGreaterThan(10)` 应该返回字符串 `10 or Under`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testGreaterThan(10) === '10 or Under');
|
assert(testGreaterThan(10) === '10 or Under');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testGreaterThan(11)` should return "Over 10"
|
`testGreaterThan(11)` 应该返回字符串 `Over 10`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testGreaterThan(11) === 'Over 10');
|
assert(testGreaterThan(11) === 'Over 10');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testGreaterThan(99)` should return "Over 10"
|
`testGreaterThan(99)` 应该返回字符串 `Over 10`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testGreaterThan(99) === 'Over 10');
|
assert(testGreaterThan(99) === 'Over 10');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testGreaterThan(100)` should return "Over 10"
|
`testGreaterThan(100)` 应该返回字符串 `Over 10`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testGreaterThan(100) === 'Over 10');
|
assert(testGreaterThan(100) === 'Over 10');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testGreaterThan(101)` should return "Over 100"
|
`testGreaterThan(101)` 应该返回字符串 `Over 100`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testGreaterThan(101) === 'Over 100');
|
assert(testGreaterThan(101) === 'Over 100');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testGreaterThan(150)` should return "Over 100"
|
`testGreaterThan(150)` 应该返回字符串 `Over 100`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testGreaterThan(150) === 'Over 100');
|
assert(testGreaterThan(150) === 'Over 100');
|
||||||
```
|
```
|
||||||
|
|
||||||
You should use the `>` operator at least twice
|
应该使用 `>` 运算符至少两次。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(code.match(/val\s*>\s*('|")*\d+('|")*/g).length > 1);
|
assert(code.match(/val\s*>\s*('|")*\d+('|")*/g).length > 1);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 56533eb9ac21ba0edf2244d6
|
id: 56533eb9ac21ba0edf2244d6
|
||||||
title: Comparison with the Less Than Operator
|
title: 小于运算符
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
videoUrl: 'https://scrimba.com/c/cNVRWtB'
|
videoUrl: 'https://scrimba.com/c/cNVRWtB'
|
||||||
forumTopicId: 16789
|
forumTopicId: 16789
|
||||||
@ -9,61 +9,63 @@ dashedName: comparison-with-the-less-than-operator
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
The <dfn>less than</dfn> operator (`<`) compares the values of two numbers. If the number to the left is less than the number to the right, it returns `true`. Otherwise, it returns `false`. Like the equality operator, <dfn>less than</dfn> operator converts data types while comparing.
|
使用小于运算符(`<`)来比较两个数字。 如果小于运算符左边的数字比右边的数字小,它会返回 `true`。 否则会返回 `false`。 与相等运算符类似,小于运算符在做比较的时候会转换值的数据类型。
|
||||||
|
|
||||||
**Examples**
|
**例如:**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
2 < 5 // true
|
2 < 5
|
||||||
'3' < 7 // true
|
'3' < 7
|
||||||
5 < 5 // false
|
5 < 5
|
||||||
3 < 2 // false
|
3 < 2
|
||||||
'8' < 4 // false
|
'8' < 4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
按顺序,这些表达式会返回 `true`、`true`、`false`、`false` 和 `false`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Add the less than operator to the indicated lines so that the return statements make sense.
|
添加小于运算符到指定行,使得函数的返回语句有意义。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`testLessThan(0)` should return "Under 25"
|
`testLessThan(0)` 应该返回字符串 `Under 25`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testLessThan(0) === 'Under 25');
|
assert(testLessThan(0) === 'Under 25');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testLessThan(24)` should return "Under 25"
|
`testLessThan(24)` 应该返回字符串 `Under 25`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testLessThan(24) === 'Under 25');
|
assert(testLessThan(24) === 'Under 25');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testLessThan(25)` should return "Under 55"
|
`testLessThan(25)` 应该返回字符串 `Under 55`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testLessThan(25) === 'Under 55');
|
assert(testLessThan(25) === 'Under 55');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testLessThan(54)` should return "Under 55"
|
`testLessThan(54)` 应该返回字符串 `Under 55`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testLessThan(54) === 'Under 55');
|
assert(testLessThan(54) === 'Under 55');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testLessThan(55)` should return "55 or Over"
|
`testLessThan(55)` 应该返回字符串 `55 or Over`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testLessThan(55) === '55 or Over');
|
assert(testLessThan(55) === '55 or Over');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testLessThan(99)` should return "55 or Over"
|
`testLessThan(99)` 应该返回字符串 `55 or Over`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testLessThan(99) === '55 or Over');
|
assert(testLessThan(99) === '55 or Over');
|
||||||
```
|
```
|
||||||
|
|
||||||
You should use the `<` operator at least twice
|
应该使用 `<` 运算符至少两次。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(code.match(/val\s*<\s*('|")*\d+('|")*/g).length > 1);
|
assert(code.match(/val\s*<\s*('|")*\d+('|")*/g).length > 1);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 56533eb9ac21ba0edf2244d3
|
id: 56533eb9ac21ba0edf2244d3
|
||||||
title: Comparison with the Strict Inequality Operator
|
title: 严格不等运算符
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
videoUrl: 'https://scrimba.com/c/cKekkUy'
|
videoUrl: 'https://scrimba.com/c/cKekkUy'
|
||||||
forumTopicId: 16791
|
forumTopicId: 16791
|
||||||
@ -9,47 +9,49 @@ dashedName: comparison-with-the-strict-inequality-operator
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
The strict inequality operator (`!==`) is the logical opposite of the strict equality operator. It means "Strictly Not Equal" and returns `false` where strict equality would return `true` and *vice versa*. Strict inequality will not convert data types.
|
严格不相等运算符(`!==`)与全等运算符是相反的。 这意味着严格不相等并返回 `false` 的地方,用严格相等运算符会返回 `true`,*反之亦然*。 严格不相等运算符不会转换值的数据类型。
|
||||||
|
|
||||||
**Examples**
|
**示例**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
3 !== 3 // false
|
3 !== 3
|
||||||
3 !== '3' // true
|
3 !== '3'
|
||||||
4 !== 3 // true
|
4 !== 3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
按顺序,这些表达式会返回 `false`、`true`、`true`。
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Add the strict inequality operator to the `if` statement so the function will return "Not Equal" when `val` is not strictly equal to `17`
|
在 `if` 语句中,添加严格不相等运算符,这样函数在当 `val` 不严格等于 `17` 的时候,会返回 `Not Equal`。
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
`testStrictNotEqual(17)` should return "Equal"
|
`testStrictNotEqual(17)` 应该返回字符串 `Equal`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testStrictNotEqual(17) === 'Equal');
|
assert(testStrictNotEqual(17) === 'Equal');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testStrictNotEqual("17")` should return "Not Equal"
|
`testStrictNotEqual("17")` 应该返回字符串 `Not Equal`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testStrictNotEqual('17') === 'Not Equal');
|
assert(testStrictNotEqual('17') === 'Not Equal');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testStrictNotEqual(12)` should return "Not Equal"
|
`testStrictNotEqual(12)` 应该返回字符串 `Not Equal`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testStrictNotEqual(12) === 'Not Equal');
|
assert(testStrictNotEqual(12) === 'Not Equal');
|
||||||
```
|
```
|
||||||
|
|
||||||
`testStrictNotEqual("bob")` should return "Not Equal"
|
`testStrictNotEqual("bob")` 应该返回字符串 `Not Equal`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(testStrictNotEqual('bob') === 'Not Equal');
|
assert(testStrictNotEqual('bob') === 'Not Equal');
|
||||||
```
|
```
|
||||||
|
|
||||||
You should use the `!==` operator
|
应该使用 `!==` 运算符。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);
|
assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);
|
||||||
|
@ -36,7 +36,7 @@ Puedes usar HTML, JavaScript y CSS para completar este proyecto. Se recomienda u
|
|||||||
|
|
||||||
**Historia de Usuario #11:** La barra de navegación debe estar siempre en la parte superior del viewport.
|
**Historia de Usuario #11:** La barra de navegación debe estar siempre en la parte superior del viewport.
|
||||||
|
|
||||||
Puedes construir tu proyecto haciendo un fork de [este CodePen](https://codepen.io/freeCodeCamp/pen/MJjpwO). O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
Puedes construir tu proyecto con <a href='https://codepen.io/pen?template=MJjpwO' target='_blank' rel='nofollow'>usando esta plantilla CodePen</a> y haciendo clic en `Save` para crear tu propio lápiz. O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
||||||
|
|
||||||
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ Puedes usar HTML, JavaScript y CSS para completar este proyecto. Se recomienda u
|
|||||||
|
|
||||||
**Historia de Usuario #15:** Mi página de aterrizaje de producto debería utilizar CSS flexbox al menos una vez.
|
**Historia de Usuario #15:** Mi página de aterrizaje de producto debería utilizar CSS flexbox al menos una vez.
|
||||||
|
|
||||||
Puedes construir tu proyecto haciendo un fork de [este CodePen](https://codepen.io/freeCodeCamp/pen/MJjpwO). O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
Puedes construir tu proyecto usando <a href='https://codepen.io/pen?template=MJjpwO' target='_blank' rel='nofollow'>esta plantilla CodePen</a> y haciendo clic en `Save` para crear tu propio pen. O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
||||||
|
|
||||||
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ Puedes usar HTML, JavaScript y CSS para completar este proyecto. Se recomienda u
|
|||||||
|
|
||||||
**Historia de Usuario #16:** Dentro del elemento form, me es presentado un botón con `id="submit"` para enviar todas mis entradas.
|
**Historia de Usuario #16:** Dentro del elemento form, me es presentado un botón con `id="submit"` para enviar todas mis entradas.
|
||||||
|
|
||||||
Puedes construir tu proyecto haciendo un fork de [este CodePen](https://codepen.io/freeCodeCamp/pen/MJjpwO). O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
Puedes construir tu proyecto usando <a href='https://codepen.io/pen?template=MJjpwO' target='_blank' rel='nofollow'>esta plantilla CodePen</a> y haciendo clic en `Save` para crear tu propio pen. O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
||||||
|
|
||||||
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ Puedes usar HTML, JavaScript y CSS para completar este proyecto. Se recomienda u
|
|||||||
|
|
||||||
**Historia de Usuario #15:** Mi página de Documentación Técnica debería usar al menos una media query.
|
**Historia de Usuario #15:** Mi página de Documentación Técnica debería usar al menos una media query.
|
||||||
|
|
||||||
Puedes construir tu proyecto haciendo un fork de [este CodePen](https://codepen.io/freeCodeCamp/pen/MJjpwO). O puedes utilizar este enlace CDN para ejecutar las pruebas en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
Puedes construir tu proyecto usando <a href='https://codepen.io/pen?template=MJjpwO' target='_blank' rel='nofollow'>esta plantilla CodePen</a> y haciendo clic en `Save` para crear tu propio pen. O puedes utilizar este enlace CDN para ejecutar las pruebas en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`
|
||||||
|
|
||||||
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todas las pruebas aprobadas.
|
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todas las pruebas aprobadas.
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ Puedes usar HTML, JavaScript y CSS para completar este proyecto. Se recomienda u
|
|||||||
|
|
||||||
**Historia de Usuario #9:** El elemento `img` debería estar centrado dentro de su elemento padre.
|
**Historia de Usuario #9:** El elemento `img` debería estar centrado dentro de su elemento padre.
|
||||||
|
|
||||||
Puedes construir tu proyecto haciendo un fork de [este CodePen](https://codepen.io/freeCodeCamp/pen/MJjpwO). O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`.
|
Puedes construir tu proyecto usando <a href='https://codepen.io/pen?template=MJjpwO' target='_blank' rel='nofollow'>esta plantilla CodePen</a> y haciendo clic en `Save` para crear tu propio pen. O puedes utilizar este enlace CDN para ejecutar los tests en cualquier entorno que desees: `https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js`.
|
||||||
|
|
||||||
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
Una vez que hayas terminado, envía la URL de tu proyecto funcional con todos los tests aprobados.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 587d7da9367417b2b2512b6a
|
id: 587d7da9367417b2b2512b6a
|
||||||
title: Return a Sorted Array Without Changing the Original Array
|
title: Devuelve un arreglo ordenado sin cambiar el arreglo original
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
forumTopicId: 301237
|
forumTopicId: 301237
|
||||||
dashedName: return-a-sorted-array-without-changing-the-original-array
|
dashedName: return-a-sorted-array-without-changing-the-original-array
|
||||||
@ -8,27 +8,27 @@ dashedName: return-a-sorted-array-without-changing-the-original-array
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
A side effect of the `sort` method is that it changes the order of the elements in the original array. In other words, it mutates the array in place. One way to avoid this is to first concatenate an empty array to the one being sorted (remember that `slice` and `concat` return a new array), then run the `sort` method.
|
Un efecto secundario del método `sort` es que cambia el orden de los elementos en el arreglo original. En otras palabras, muta el arreglo en su sitio. Una forma de evitar esto es concatenar primero un arreglo vacío al que está siendo ordenado (recuerda que `slice` y `concat` devuelven un nuevo arreglo), luego ejecutar el método `sort`.
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Use the `sort` method in the `nonMutatingSort` function to sort the elements of an array in ascending order. The function should return a new array, and not mutate the `globalArray` variable.
|
Utiliza el método `sort` en la función `nonMutatingSort` para ordenar los elementos de un arreglo en orden ascendente. La función debe devolver un nuevo arreglo y no mutar la variable `globalArray`.
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
Your code should use the `sort` method.
|
Tu código debe usar el método `sort`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(nonMutatingSort.toString().match(/\.sort/g));
|
assert(nonMutatingSort.toString().match(/\.sort/g));
|
||||||
```
|
```
|
||||||
|
|
||||||
The `globalArray` variable should not change.
|
La variable `globalArray` no debe cambiar.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(JSON.stringify(globalArray) === JSON.stringify([5, 6, 3, 2, 9]));
|
assert(JSON.stringify(globalArray) === JSON.stringify([5, 6, 3, 2, 9]));
|
||||||
```
|
```
|
||||||
|
|
||||||
`nonMutatingSort(globalArray)` should return `[2, 3, 5, 6, 9]`.
|
`nonMutatingSort(globalArray)` debe devolver `[2, 3, 5, 6, 9]`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -37,18 +37,32 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`nonMutatingSort(globalArray)` should not be hard coded.
|
`nonMutatingSort(globalArray)` no debe ser programada manualmente.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!nonMutatingSort.toString().match(/[23569]/g));
|
assert(!nonMutatingSort.toString().match(/[23569]/g));
|
||||||
```
|
```
|
||||||
|
|
||||||
The function should return a new array, not the array passed to it.
|
La función debe devolver un nuevo arreglo, no el arreglo que se le pasa.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(nonMutatingSort(globalArray) !== globalArray);
|
assert(nonMutatingSort(globalArray) !== globalArray);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`nonMutatingSort([1, 30, 4, 21, 100000])` debe devolver `[1, 4, 21, 30, 100000]`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert(JSON.stringify(nonMutatingSort([1, 30, 4, 21, 100000])) ===
|
||||||
|
JSON.stringify([1, 4, 21, 30, 100000]))
|
||||||
|
```
|
||||||
|
|
||||||
|
`nonMutatingSort([140000, 104, 99])` debe devolver `[99, 104, 140000]`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) ===
|
||||||
|
JSON.stringify([99, 104, 140000]))
|
||||||
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
|
||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 587d7b90367417b2b2512b65
|
id: 587d7b90367417b2b2512b65
|
||||||
title: Return Part of an Array Using the slice Method
|
title: Devolver parte de un arreglo mediante el método slice
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
forumTopicId: 301239
|
forumTopicId: 301239
|
||||||
dashedName: return-part-of-an-array-using-the-slice-method
|
dashedName: return-part-of-an-array-using-the-slice-method
|
||||||
@ -8,29 +8,30 @@ dashedName: return-part-of-an-array-using-the-slice-method
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
The `slice` method returns a copy of certain elements of an array. It can take two arguments, the first gives the index of where to begin the slice, the second is the index for where to end the slice (and it's non-inclusive). If the arguments are not provided, the default is to start at the beginning of the array through the end, which is an easy way to make a copy of the entire array. The `slice` method does not mutate the original array, but returns a new one.
|
El método `slice` devuelve una copia de ciertos elementos de un arreglo. Puede tomar dos argumentos, el primero da el índice de dónde comenzar el corte, el segundo es el índice de dónde terminar el corte (y no es inclusivo). Si no se proporcionan los argumentos, el valor predeterminado es comenzar desde el principio del arreglo hasta el final, la cual es una manera fácil de hacer una copia de todo el arreglo. El método `slice` no muta el arreglo original, pero devuelve uno nuevo.
|
||||||
|
|
||||||
Here's an example:
|
Por ejemplo:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var arr = ["Cat", "Dog", "Tiger", "Zebra"];
|
var arr = ["Cat", "Dog", "Tiger", "Zebra"];
|
||||||
var newArray = arr.slice(1, 3);
|
var newArray = arr.slice(1, 3);
|
||||||
// Sets newArray to ["Dog", "Tiger"]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`newArray` tendría el valor de `["Dog", "Tiger"]`.
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Use the `slice` method in the `sliceArray` function to return part of the `anim` array given the provided `beginSlice` and `endSlice` indices. The function should return an array.
|
Utiliza el método `slice` en la función `sliceArray` para retornar parte del arreglo `anim` dados los índices `beginSlice` y `endSlice`. La función debe devolver un arreglo.
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
Your code should use the `slice` method.
|
Tu código debe usar el método `slice`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(code.match(/\.slice/g));
|
assert(code.match(/\.slice/g));
|
||||||
```
|
```
|
||||||
|
|
||||||
The `inputAnim` variable should not change.
|
La variable `inputAnim` no debe cambiar.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -39,7 +40,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`sliceArray(["Cat", "Dog", "Tiger", "Zebra", "Ant"], 1, 3)` should return `["Dog", "Tiger"]`.
|
`sliceArray(["Cat", "Dog", "Tiger", "Zebra", "Ant"], 1, 3)` debe devolver `["Dog", "Tiger"]`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -48,7 +49,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`sliceArray(["Cat", "Dog", "Tiger", "Zebra", "Ant"], 0, 1)` should return `["Cat"]`.
|
`sliceArray(["Cat", "Dog", "Tiger", "Zebra", "Ant"], 0, 1)` debe devolver `["Cat"]`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -57,7 +58,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`sliceArray(["Cat", "Dog", "Tiger", "Zebra", "Ant"], 1, 4)` should return `["Dog", "Tiger", "Zebra"]`.
|
`sliceArray(["Cat", "Dog", "Tiger", "Zebra", "Ant"], 1, 4)` debe devolver `["Dog", "Tiger", "Zebra"]`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: 587d7da9367417b2b2512b69
|
id: 587d7da9367417b2b2512b69
|
||||||
title: Sort an Array Alphabetically using the sort Method
|
title: Ordena un arreglo alfabéticamente con el método sort
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
forumTopicId: 18303
|
forumTopicId: 18303
|
||||||
dashedName: sort-an-array-alphabetically-using-the-sort-method
|
dashedName: sort-an-array-alphabetically-using-the-sort-method
|
||||||
@ -8,9 +8,9 @@ dashedName: sort-an-array-alphabetically-using-the-sort-method
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
The `sort` method sorts the elements of an array according to the callback function.
|
El método `sort` ordena los elementos de un arreglo de acuerdo a la función "callback".
|
||||||
|
|
||||||
For example:
|
Por ejemplo:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function ascendingOrder(arr) {
|
function ascendingOrder(arr) {
|
||||||
@ -19,32 +19,36 @@ function ascendingOrder(arr) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
ascendingOrder([1, 5, 2, 3, 4]);
|
ascendingOrder([1, 5, 2, 3, 4]);
|
||||||
// Returns [1, 2, 3, 4, 5]
|
```
|
||||||
|
|
||||||
|
Esto devolvería el valor de `[1, 2, 3, 4, 5]`.
|
||||||
|
|
||||||
|
```js
|
||||||
function reverseAlpha(arr) {
|
function reverseAlpha(arr) {
|
||||||
return arr.sort(function(a, b) {
|
return arr.sort(function(a, b) {
|
||||||
return a === b ? 0 : a < b ? 1 : -1;
|
return a === b ? 0 : a < b ? 1 : -1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
reverseAlpha(['l', 'h', 'z', 'b', 's']);
|
reverseAlpha(['l', 'h', 'z', 'b', 's']);
|
||||||
// Returns ['z', 's', 'l', 'h', 'b']
|
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript's default sorting method is by string Unicode point value, which may return unexpected results. Therefore, it is encouraged to provide a callback function to specify how to sort the array items. When such a callback function, normally called `compareFunction`, is supplied, the array elements are sorted according to the return value of the `compareFunction`: If `compareFunction(a,b)` returns a value less than 0 for two elements `a` and `b`, then `a` will come before `b`. If `compareFunction(a,b)` returns a value greater than 0 for two elements `a` and `b`, then `b` will come before `a`. If `compareFunction(a,b)` returns a value equal to 0 for two elements `a` and `b`, then `a` and `b` will remain unchanged.
|
Esto devolvería el valor de `['z', 's', 'l', 'h', 'b']`.
|
||||||
|
|
||||||
|
Por defecto, JavaScript ordena basándose en el valor "Unicode" de la cadena de caracteres, lo cual puede dar resultados inesperados. Por lo tanto, se recomienda proporcionar una función "callback" para especificar cómo se deben ordenar los elementos del arreglo. Cuando se proporciona dicha función "callback", normalmente llamada `compareFunction`, los elementos del arreglo se ordenan de acuerdo al valor que devuelve la función `compareFunction`: Si `compareFunction(a,b)` devuelve un valor menor a 0 para dos elementos `a` y `b`, entonces `a` irá antes que `b`. Si `compareFunction(a,b)` devuelve un valor mayor a 0 para dos elementos `a` y `b`, entonces `b` irá antes que `a`. Si `compareFunction(a,b)` devuelve un valor igual a 0 para dos elementos `a` y `b`, entonces `a` y `b` se dejarán sin cambios.
|
||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Use the `sort` method in the `alphabeticalOrder` function to sort the elements of `arr` in alphabetical order.
|
Utiliza el método `sort` en la función `alphabeticalOrder` para ordenar los elementos de `arr` en orden alfabético.
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
Your code should use the `sort` method.
|
Tu código debe usar el método `sort`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(code.match(/\.sort/g));
|
assert(code.match(/\.sort/g));
|
||||||
```
|
```
|
||||||
|
|
||||||
`alphabeticalOrder(["a", "d", "c", "a", "z", "g"])` should return `["a", "a", "c", "d", "g", "z"]`.
|
`alphabeticalOrder(["a", "d", "c", "a", "z", "g"])` debe devolver `["a", "a", "c", "d", "g", "z"]`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -53,7 +57,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`alphabeticalOrder(["x", "h", "a", "m", "n", "m"])` should return `["a", "h", "m", "m", "n", "x"]`.
|
`alphabeticalOrder(["x", "h", "a", "m", "n", "m"])` debe devolver `["a", "h", "m", "m", "n", "x"]`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
@ -62,7 +66,7 @@ assert(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
`alphabeticalOrder(["a", "a", "a", "a", "x", "t"])` should return `["a", "a", "a", "a", "t", "x"]`.
|
`alphabeticalOrder(["a", "a", "a", "a", "x", "t"])` debe devolver `["a", "a", "a", "a", "t", "x"]`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
|
Reference in New Issue
Block a user