Skip to content

Commit 1681ed7

Browse files
Merge pull request #25 from Violet-Bora-Lee/master
콜백, 프라미스 재 리뷰 및 배열 메서드 번역
2 parents 63d6dbd + d586c22 commit 1681ed7

File tree

5 files changed

+95
-98
lines changed

5 files changed

+95
-98
lines changed

1-js/05-data-types/05-array-methods/article.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,22 @@ alert(arr); // *!*1, 2, 15*/!*
418418

419419
이제 의도한 대로 숫자가 오름차순으로 정렬되었습니다.
420420

421-
Let's step aside and think what's happening. The `arr` can be array of anything, right?
422-
It may contain numbers or strings or html elements or whatever. We have a set of *something*.
423-
To sort it, we need an *ordering function* that knows how to compare its elements.
424-
The default is a string order.
421+
읽는 걸 멈추고 이 메서드가 어떻게 동작하는지 잠시 생각해 보도록 합시다. `arr`의 요소는 어떤 형태의 값이든 가능합니다. 숫자, 문자열, html 요소 등 모든것이 가능하죠. *무언가*로 구성된 집합이 있는 상황입니다. 이 집합을 정렬하려면 *순서를 매겨주는 함수*가 필요합니다. 요소를 어떤 기준으로 비교하고 정렬할지를 이 함수에서 정의합니다. sort 메서드는 기본적으로 문자열 집합을 가정하고 요소를 비교, 정렬합니다.
425422

426-
The `arr.sort(fn)` method has a built-in implementation of sorting algorithm. We don't need to care how it exactly works (an optimized [quicksort](https://en.wikipedia.org/wiki/Quicksort) most of the time). It will walk the array, compare its elements using the provided function and reorder them, all we need is to provide the `fn` which does the comparison.
423+
`arr.sort(fn)` 메서드의 정렬 알고리즘은 내부에 구현되어 있습니다. (대부분 최적화된 [quicksort](https://en.wikipedia.org/wiki/Quicksort)를 사용하는데) 내부 알고리즘이 어떻게 작동하는지는 상관할 필요가 없습니다. 내부에 구현된 알고리즘은 배열내를 돌아다니며 요소를 비교하고, 제공된 함수를 기준으로 요소를 재 정렬합니다. 개발자는 비교에 쓰이는 `fn` 만 제공해 주면 됩니다.
427424

428-
By the way, if we ever want to know which elements are compared -- nothing prevents from alerting them:
425+
정렬 과정에서 어떤 요소끼리 비교가 일어났는지 확인하고 싶다면 아래 코드를 통해 확인하면 됩니다.
429426

430427
```js run
431428
[1, -2, 15, 2, 0, 8].sort(function(a, b) {
432429
alert( a + " <> " + b );
433430
});
434431
```
435432

436-
The algorithm may compare an element multiple times in the process, but it tries to make as few comparisons as possible.
433+
정렬에 쓰이는 알고리즘은 정렬 과정에서 요소를 여러번 비교합니다. 하지만 비교를 가능한 한 적게 하는 방식으로 구현되어 있습니다.
437434

438435

439-
````smart header="A comparison function may return any number"
436+
````smart header="비교에 쓰이는 함수는 어떤 숫자던 반환할 수 있습니다."
440437
Actually, a comparison function is only required to return a positive number to say "greater" and a negative number to say "less".
441438
442439
That allows to write shorter functions:

1-js/11-async/01-callbacks/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ loadScript('/my/script.js', function(error, script) {
171171
});
172172
```
173173

174-
`loadScript` 함수는 자주 쓰이는 방식들로 만들었습니다. 여기서 에러 처리는 "error-first callback" 스타일이라 부르는 방식으로 작성되었습니다.
174+
`loadScript` 함수는 자주 쓰이는 방식들로 만들었습니다. 여기서 에러 처리는 "오류 우선 콜백(error-first callback)" 스타일이라 부르는 방식으로 작성되었습니다.
175175

176-
관례는 다음과 같습니다.
176+
오류 우선 콜백은 다음 관례를 따릅니다.
177177
1. `callback`의 첫 번째 인수는 에러를 위해 남겨둡니다. 에러가 발생하면 이 인수를 이용해 `callback(err)`이 호출됩니다.
178178
2. 두 번째 인수(필요하면 또 다른 인수)는 에러가 발생하지 않았을 때를 위해 남겨둡니다. 원하는 동작이 성공한 경우엔 `callback(null, result1, result2...)`이 호출됩니다.
179179

180-
이처럼 "error-first callback" 스타일을 사용해 콜백 함수를 작성하면, 단일 `콜백` 함수는 실패와 성공 모두를 처리할 수 있게 됩니다.
180+
이처럼 "오류 우선 콜백" 스타일을 사용해 콜백 함수를 작성하면, 단일 `콜백` 함수는 실패와 성공 모두를 처리할 수 있게 됩니다.
181181

182182
## 멸망의 피라미드
183183

0 commit comments

Comments
 (0)