-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from javascript-tutorial/leviding-patch-4
Update translation of 1-js/05-data-types/05-array-methods
- Loading branch information
Showing
23 changed files
with
356 additions
and
273 deletions.
There are no files selected for viewing
10 changes: 6 additions & 4 deletions
10
1-js/05-data-types/05-array-methods/1-camelcase/_js.view/solution.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
function camelize(str) { | ||
return str | ||
.split('-') // my-long-word -> ['my', 'long', 'word'] | ||
.map( | ||
.split('-') // splits 'my-long-word' into array ['my', 'long', 'word'] | ||
.map( | ||
// capitalizes first letters of all array items except the first one | ||
// converts ['my', 'long', 'word'] into ['my', 'Long', 'Word'] | ||
(word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1) | ||
) // ['my', 'long', 'word'] -> ['my', 'Long', 'Word'] | ||
.join(''); // ['my', 'Long', 'Word'] -> myLongWord | ||
) | ||
.join(''); // joins ['my', 'Long', 'Word'] into 'myLongWord' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```js run demo | ||
function filterRange(arr, a, b) { | ||
// added brackets around the expression for better readability | ||
return arr.filter(item => (a <= item && item <= b)); | ||
} | ||
|
||
let arr = [5, 3, 8, 1]; | ||
|
||
let filtered = filterRange(arr, 1, 4); | ||
|
||
alert( filtered ); // 3,1 (matching values) | ||
|
||
alert( arr ); // 5,3,8,1 (not modified) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
```js run demo | ||
function filterRangeInPlace(arr, a, b) { | ||
|
||
for (let i = 0; i < arr.length; i++) { | ||
let val = arr[i]; | ||
|
||
// remove if outside of the interval | ||
if (val < a || val > b) { | ||
arr.splice(i, 1); | ||
i--; | ||
} | ||
} | ||
|
||
} | ||
|
||
let arr = [5, 3, 8, 1]; | ||
|
||
filterRangeInPlace(arr, 1, 4); // removed the numbers except from 1 to 4 | ||
|
||
alert( arr ); // [3, 1] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
1-js/05-data-types/05-array-methods/6-calculator-extendable/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
- 请注意如何存储方法。它们只是被添加到 `this.methods` 属性中。 | ||
- 所有测试和数值转换都在 `calculate` 方法中完成。将来它可能会扩展到支持更复杂的表达式。 | ||
- 请注意方法的存储方式。它们只是被添加到 `this.methods` 属性中。 | ||
- 所有检测和数字转换都通过 `calculate` 方法完成。将来可能会扩展它以支持更复杂的表达式。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.