Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions 1-js/05-data-types/11-date/1-new-date/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

따라서 2월은 숫자 1을 사용해 만듭니다.

Here's an example with numbers as date components:

Here's an example with numbers as date components:
숫자로 날짜를 생성하는 예제는 다음과 같습니다.

```js run
//new Date(year, month, date, hour, minute, second, millisecond)
let d1 = new Date(2012, 1, 20, 3, 12);
alert( d1 );
```
We could also create a date from a string, like this:

문자열로도 다음과 같이 날짜를 만들 수 있습니다.

```js run
//new Date(datastring)
<<<<<<< HEAD
let d2 = new Date("February 20, 2012 03:12:00");
=======
let d2 = new Date("2012-02-20T03:12");
>>>>>>> upstream/master
alert( d2 );
```
37 changes: 2 additions & 35 deletions 1-js/05-data-types/11-date/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,10 @@ Date 객체를 활용하면 생성 및 수정 시간을 저장하거나 시간
`new Date(year, month, date, hours, minutes, seconds, ms)`
: 주어진 인수를 조합해 만들 수 있는 날짜가 저장된 객체가 반환됩니다(지역 시간대 기준). 첫 번째와 두 번째 인수만 필수값입니다.

<<<<<<< HEAD
- `year`는 반드시 네 자리 숫자여야 합니다. `2013`은 괜찮고 `98`은 괜찮지 않습니다.
- `year`는 네 자리 숫자를 사용하는 것이 좋습니다. 호환성을 위해 두 자리 숫자도 허용되며 `19xx`로 간주합니다. 예를 들어 여기서 `98`은 `1998`과 같지만, 네 자리 숫자를 사용하는 것을 강력히 권장합니다.
- `month`는 `0`(1월)부터 `11`(12월) 사이의 숫자여야 합니다.
- `date`는 일을 나타내는데, 값이 없는 경우엔 1일로 처리됩니다.
- `hours/minutes/seconds/ms`에 값이 없는 경우엔 `0`으로 처리됩니다.
=======
- The `year` should have 4 digits. For compatibility, 2 digits are also accepted and considered `19xx`, e.g. `98` is the same as `1998` here, but always using 4 digits is strongly encouraged.
- The `month` count starts with `0` (Jan), up to `11` (Dec).
- The `date` parameter is actually the day of month, if absent then `1` is assumed.
- If `hours/minutes/seconds/ms` is absent, they are assumed to be equal `0`.
>>>>>>> upstream/master

예시:

Expand All @@ -76,11 +69,7 @@ Date 객체를 활용하면 생성 및 수정 시간을 저장하거나 시간
new Date(2011, 0, 1); // hours를 비롯한 인수는 기본값이 0이므로 위와 동일
```

<<<<<<< HEAD
최소 정밀도는 1밀리초(1/1000초)입니다.
=======
The maximal precision is 1 ms (1/1000 sec):
>>>>>>> upstream/master

```js run
let date = new Date(2011, 0, 1, 2, 3, 4, 567);
Expand Down Expand Up @@ -359,11 +348,7 @@ let time1 = 0;
let time2 = 0;

*!*
<<<<<<< HEAD
// 함수 bench를 각 함수(diffSubtract, diffGetTime)별로 10번씩 돌립니다.
=======
// run bench(diffSubtract) and bench(diffGetTime) each 10 times alternating
>>>>>>> upstream/master
// 함수 bench를 각 함수(diffSubtract, diffGetTime)별로 번갈아 가며 10번씩 돌립니다.
for (let i = 0; i < 10; i++) {
time1 += bench(diffSubtract);
time2 += bench(diffGetTime);
Expand Down Expand Up @@ -391,11 +376,7 @@ for (let i = 0; i < 10; i++) {
```warn header="세밀한 벤치마킹을 할 때는 주의하세요"
모던 자바스크립트 엔진은 최적화를 많이 합니다. 이로 인해 '만들어진 테스트'가 '실제 사례'와는 결과가 다를 수 있습니다. 특히 연산자, 내장 함수와 같이 아주 작은 것일수록 더 결과가 다를 수 있습니다. 그러니 진지하게 성능을 이해하고 싶다면 자바스크립트 엔진이 어떻게 동작하는지 공부하시길 바랍니다. 그러면 아마 세밀한 벤치마킹을 할 필요가 없을 겁니다.

<<<<<<< HEAD
<http://mrale.ph>에서 V8 엔진을 설명한 좋은 글들을 보실 수 있습니다.
=======
The great pack of articles about V8 can be found at <https://mrale.ph>.
>>>>>>> upstream/master
```

## Date.parse와 문자열
Expand All @@ -404,17 +385,10 @@ The great pack of articles about V8 can be found at <https://mrale.ph>.

단, 문자열의 형식은 `YYYY-MM-DDTHH:mm:ss.sssZ`처럼 생겨야 합니다.

<<<<<<< HEAD
- `YYYY-MM-DD` -- 날짜(연-월-일)
- `"T"` -- 구분 기호로 쓰임
- `HH:mm:ss.sss` -- 시:분:초.밀리초
- `'Z'`(옵션) -- `+-hh:mm` 형식의 시간대를 나타냄. `Z` 한 글자인 경우엔 UTC+0을 나타냄
=======
- `YYYY-MM-DD` -- is the date: year-month-day.
- The character `"T"` is used as the delimiter.
- `HH:mm:ss.sss` -- is the time: hours, minutes, seconds and milliseconds.
- The optional `'Z'` part denotes the time zone in the format `+-hh:mm`. A single letter `Z` would mean UTC+0.
>>>>>>> upstream/master

`YYYY-MM-DD`, `YYYY-MM`, `YYYY`같이 더 짧은 문자열 형식도 가능합니다.

Expand Down Expand Up @@ -450,17 +424,10 @@ alert(date);
간혹 밀리초보다 더 정확한 시간 측정이 필요할 때가 있습니다. 자바스크립트는 마이크로초(1/1,000,000초)를 지원하진 않지만 대다수의 호스트 환경은 마이크로초를 지원합니다. 브라우저 환경의 메서드 [performance.now()](mdn:api/Performance/now)는 페이지 로딩에 걸리는 밀리초를 반환해주는데, 반환되는 숫자는 소수점 아래 세 자리까지 지원합니다.

```js run
<<<<<<< HEAD
alert(`페이지 로딩이 ${performance.now()}밀리초 전에 시작되었습니다.`);
// 얼럿 창에 "페이지 로딩이 34731.26000000001밀리초 전에 시작되었습니다."와 유사한 메시지가 뜰 텐데
// 여기서 '.26'은 마이크로초(260마이크로초)를 나타냅니다.
// 소수점 아래 숫자 세 개 이후의 숫자는 정밀도 에러때문에 보이는 숫자이므로 소수점 아래 숫자 세 개만 유효합니다.
=======
alert(`Loading started ${performance.now()}ms ago`);
// Something like: "Loading started 34731.26000000001ms ago"
// .26 is microseconds (260 microseconds)
// more than 3 digits after the decimal point are precision errors, only the first 3 are correct
>>>>>>> upstream/master
```

Node.js에선 `microtime` 모듈 등을 사용해 마이크로초를 사용할 수 있습니다. 자바스크립트가 구동되는 대다수의 호스트 환경과 기기에서 마이크로초를 지원하고 있는데 `Date` 객체만 마이크로초를 지원하지 않습니다.
22 changes: 2 additions & 20 deletions 1-js/05-data-types/12-json/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ alert(user); // {name: "John", age: 30}

## JSON.stringify

<<<<<<< HEAD
[JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation)은 값이나 객체를 나타내주는 범용 포맷으로, [RFC 4627](http://tools.ietf.org/html/rfc4627) 표준에 정의되어 있습니다. JSON은 본래 자바스크립트에서 사용할 목적으로 만들어진 포맷입니다. 그런데 라이브러리를 사용하면 자바스크립트가 아닌 언어에서도 JSON을 충분히 다룰 수 있어서, JSON을 데이터 교환 목적으로 사용하는 경우가 많습니다. 특히 클라이언트 측 언어가 자바스크립트일 때 말이죠. 서버 측 언어는 무엇이든 상관없습니다.
=======
The [JSON](https://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](https://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.
>>>>>>> upstream/master

자바스크립트가 제공하는 JSON 관련 메서드는 아래와 같습니다.

Expand Down Expand Up @@ -108,15 +104,9 @@ JSON은 데이터 교환을 목적으로 만들어진 언어에 종속되지 않

`JSON.stringify` 호출 시 무시되는 프로퍼티는 아래와 같습니다.

<<<<<<< HEAD
- 함수 프로퍼티 (메서드)
- 심볼형 프로퍼티 (키가 심볼인 프로퍼티)
- 값이 `undefined`인 프로퍼티
=======
- Function properties (methods).
- Symbolic keys and values.
- Properties that store `undefined`.
>>>>>>> upstream/master

```js run
let user = {
Expand Down Expand Up @@ -338,13 +328,9 @@ alert(JSON.stringify(user, null, 2));
*/
```

<<<<<<< HEAD
이처럼 매개변수 `space`는 로깅이나 가독성을 높이는 목적으로 사용됩니다.
=======
The third argument can also be a string. In this case, the string is used for indentation instead of a number of spaces.
세 번째 인수로 문자열을 전달할 수도 있습니다. 이 경우 공백 개수 대신 해당 문자열이 들여쓰기에 사용됩니다.

The `space` parameter is used solely for logging and nice-output purposes.
>>>>>>> upstream/master
이처럼 매개변수 `space`는 로깅이나 가독성을 높이는 목적으로 사용됩니다.

## 커스텀 "toJSON"

Expand Down Expand Up @@ -464,11 +450,7 @@ let json = `{

JSON은 주석을 지원하지 않는다는 점도 기억해 놓으시기 바랍니다. 주석을 추가하면 유효하지 않은 형식이 됩니다.

<<<<<<< HEAD
키를 큰따옴표로 감싸지 않아도 되고 주석도 지원해주는 [JSON5](http://json5.org/)라는 포맷도 있는데, 이 포맷은 자바스크립트 명세서에서 정의하지 않은 독자적인 라이브러리입니다.
=======
There's another format named [JSON5](https://json5.org/), which allows unquoted keys, comments etc. But this is a standalone library, not in the specification of the language.
>>>>>>> upstream/master

JSON 포맷이 까다로운 규칙을 가지게 된 이유는 개발자의 귀차니즘 때문이 아니고, 쉽고 빠르며 신뢰할 수 있을 만한 파싱 알고리즘을 구현하기 위해서입니다.

Expand Down
4 changes: 0 additions & 4 deletions 1-js/06-advanced-functions/01-recursion/01-sum-to/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,4 @@ alert( sumTo(100) );

반복을 사용하는 방법은 두 번째로 빠릅니다. 재귀를 사용하는 방법과 반복문을 사용하는 방법 모두 같은 수의 숫자를 더하는 것에서 같지만, 재귀를 사용하는 방법은 중첩 호출과 실행 스택 관리가 추가로 필요하기 때문에 더 많은 자원을 소비합니다. 따라서 속도가 더 느리죠.

<<<<<<< HEAD
더 생각해보기 2: 몇몇 자바스크립트 엔진은 'tail call' 최적화를 지원합니다. 위 함수 `sumTo`처럼 함수가 가장 마지막으로 수행하는 연산이 재귀 호출이라면 외부 함수는 실행을 다시 시작할 필요가 없기 때문에 엔진은 실행 컨텍스트를 기억할 필요가 없어집니다. 메모리 부담이 사라지는 거죠. 그렇기 때문에 `sumTo(100000)`같은 계산이 가능한 것입니다. 그런데 자바스크립트 엔진이 tail call 최적화를 지원하지 않는다면(대부분의 엔진이 이를 지원하지 않습니다) 엔진에 설정된 스택 사이즈 제한을 넘었기 때문에 최대 스택 사이즈 초과 에러가 발생합니다.
=======
P.P.S. Some engines support the "tail call" optimization: if a recursive call is the very last one in the function, with no other calculations performed, then the outer function will not need to resume the execution, so the engine doesn't need to remember its execution context. That removes the burden on memory. But if the JavaScript engine does not support tail call optimization (most of them don't), there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size.
>>>>>>> upstream/master
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<<<<<<< HEAD
팩토리얼은 그 정의에 따라 `n!`을 `n * (n-1)!`로 바꿔쓸 수 있습니다.
=======
By definition, a factorial `n!` can be written as `n * (n-1)!`.
>>>>>>> upstream/master

따라서 `factorial(n)`의 결과는 `n`과 `factorial(n-1)`의 결과를 곱한 값이 되겠죠. 함수의 인수는 `n-1`에서 `1`이 될 때까지 점점 줄어들 겁니다.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ printReverseList(list);

# 반복문을 기반으로 하는 방법

<<<<<<< HEAD
리스트를 원래 순서대로 출력하는 방법보다 역시 까다롭습니다.
=======
The loop variant is also a little bit more complicated than the direct output.
>>>>>>> upstream/master
반복문을 기반으로 하는 방법도 직접 출력하는 방법보다 조금 더 복잡합니다.

`list`의 마지막 값을 바로 구할 수 있는 방법이 없기 때문입니다. 마지막 값을 시작으로 '역행'할 수 없는 상황이죠.

Expand Down
16 changes: 0 additions & 16 deletions 1-js/06-advanced-functions/01-recursion/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ function pow(x, n) {
</li>
</ul>

<<<<<<< HEAD
위 그림은 함수 실행이 시작되는 순간을 나타낸 것입니다. 지금 상태론 조건 `n == 1`을 만족하지 못하므로 실행 흐름은 `if`의 두 번째 분기로 넘어갑니다.
=======
That's when the function starts to execute. The condition `n == 1` is falsy, so the flow continues into the second branch of `if`:
>>>>>>> upstream/master

```js run
function pow(x, n) {
Expand Down Expand Up @@ -192,11 +188,7 @@ alert( pow(2, 3) );
이전 컨텍스트에 변수 정보, 코드가 일시 중단된 줄에 대한 정보가 저장되어있기 때문에 서브 호출이 끝났을 때 이전 컨텍스트가 문제없이 다시 시작됩니다.

```smart
<<<<<<< HEAD
예시엔 한 줄에 서브 호출 하나만 있기 때문에, 그림에서 '줄'이라는 단어를 사용했습니다. 하지만 한 줄에는 `pow(…) + pow(…) + somethingElse(…)` 같이 복수의 서브 호출이 있을 수 있습니다.
=======
Here in the picture we use the word "line", as in our example there's only one subcall in line, but generally a single line of code may contain multiple subcalls, like `pow(…) + pow(…) + somethingElse(…)`.
>>>>>>> upstream/master

따라서 좀 더 정확히는 실행이 '서브 호출 바로 직후'에 시작된다고 이야기 할 수 있습니다.
```
Expand Down Expand Up @@ -293,11 +285,7 @@ function pow(x, n) {

**재귀를 이용해 작성한 코드는 반복문을 사용한 코드로 다시 작성할 수 있습니다. 반복문을 사용하면 대개 함수 호출의 비용(메모리 사용)이 절약됩니다.**

<<<<<<< HEAD
하지만 코드를 다시 작성해도 큰 개선이 없는 경우가 있습니다. 조건에 따라 함수가 다른 재귀 서브 호출을 하고 그 결과를 합칠 때가 그렇습니다. 분기문이 복잡하게 얽혀있을 때도 메모리가 크게 절약되지 않습니다. 이런 경우엔 최적화가 필요하지 않을 수 있고 최적화에 드는 노력이 무용지물일 수 있습니다.
=======
...But sometimes the rewrite is non-trivial, especially when a function uses different recursive subcalls depending on conditions and merges their results or when the branching is more intricate. And the optimization may be unneeded and totally not worth the efforts.
>>>>>>> upstream/master

재귀를 사용하면 코드가 짧아지고 코드 이해도가 높아지며 유지보수에도 이점이 있습니다. 모든 곳에서 메모리 최적화를 신경 써서 코드를 작성해야 하는 것은 아닙니다. 우리가 필요한 것은 좋은 코드입니다. 이런 이유 때문에 재귀를 사용합니다.

Expand Down Expand Up @@ -547,11 +535,7 @@ list.next = list.next.next;
list = {value, next -> list}
```

<<<<<<< HEAD
HTML 문서의 HTML 요소 트리나 위에서 다룬 부서를 나타내는 트리 역시 재귀적인 자료 구조로 만들었습니다. 이렇게 재귀적인 자료 구조를 사용하면 가지가 여러 개인데 각 가지가 여러 가지로 뻗쳐 나가는 형태로 자료 구조를 만들 수 있습니다.
=======
Trees like HTML elements tree or the department tree from this chapter are also naturally recursive: they have branches and every branch can have other branches.
>>>>>>> upstream/master

예시에서 구현한 `sumSalary`같은 재귀 함수를 사용하면 각 분기(가지)를 순회할 수 있습니다.

Expand Down
32 changes: 5 additions & 27 deletions 1-js/06-advanced-functions/02-rest-parameters-spread/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ function sum(a, b) {
alert( sum(1, 2, 3, 4, 5) );
```

<<<<<<< HEAD
함수를 정의할 땐 인수를 두 개만 받도록 하고, 실제 함수를 호출할 땐 이보다 더 많은 '여분의' 인수를 전달했지만, 에러가 발생하지 않았습니다. 다만 반환 값은 처음 두 개의 인수만을 사용해 계산됩니다.
=======
There will be no error because of "excessive" arguments. But of course in the result only the first two will be counted, so the result in the code above is `3`.
>>>>>>> upstream/master
함수를 정의할 땐 인수를 두 개만 받도록 하고, 실제 함수를 호출할 땐 이보다 더 많은 '여분의' 인수를 전달했지만, 에러가 발생하지 않았습니다. 다만 결과를 계산할 때는 처음 두 개의 인수만 사용하므로 위 코드의 결과는 `3`이 됩니다.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뒤 문장 번역해 주신 부분은 잘 해주신 거 같은데 앞 문장이 '여분의' 이 부분이 잘드러나고 간략하면 좋을 거 같은데 아래와 같은 표현은 어떠신가요?
'여분의' 인수가 있어도 에러는 발생하지 않습니다. 다만 결과를 계산할 때는 처음 두 개의 인수만 사용하므로 위 코드의 결과는 '3'이 됩니다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 처음에는 그렇게 생각했는데 이전에 번역하신 분이 앞의 내용까지 고려해서 지금처럼 번역을 해주신 것 같더라구요.
앞서 번역을 해주신 분의 의도가 저는 해석하는 데에 있어서 더 좋다고 판단되어서 이전의 번역을 최대한 건들지 않고 뒷 문장만 번역을 추가하려고 해서 지금과 같은 번역이 완성 되었습니다.

앞에 실제 예시로 함수 SUM에 인수를 2개 넣도록 선언하고 5개의 인수를 넣는 예시가 있는데 이러한 예시를 고려한 한글 번역이 영어 번역보다 더 적절하다고 생각해서 이렇게 번역을 유지했습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음 읽는 사람 관점에서 코드의 맥락도 생각하면 기존 번역이 자연스러운 거 같네요!
그럼 리뷰 완료하겠습니다


이렇게 여분의 매개변수는 그 값들을 담을 배열 이름을 마침표 세 개 `...`뒤에 붙여주면 함수 선언부에 포함시킬 수 있습니다. 이때 마침표 세 개 `...`는 "남아있는 매개변수들을 한데 모아 배열에 집어넣어라."는 것을 의미합니다.

Expand Down Expand Up @@ -229,28 +225,19 @@ alert( Array.from(str) ); // H,e,l,l,o
이런 이유때문에 무언가를 배열로 바꿀 때는 전개 구문보다 `Array.from`이 보편적으로 사용됩니다.


<<<<<<< HEAD
## 배열과 객체의 복사본 만들기
=======
## Copy an array/object
>>>>>>> upstream/master

[참조에 의한 객체 복사](info:object-copy#cloning-and-merging-object-assign) 챕터에서 `Object.assign()`을 사용해 객체를 복사한 예시를 떠올려봅시다.

`Object.assign()` 말고도 스프레드 문법을 사용하면 배열과 객체를 복사할 수 있습니다.

```js run
let arr = [1, 2, 3];
<<<<<<< HEAD
let arrCopy = [...arr]; // 배열을 펼쳐서 각 요소를 분리후, 매개변수 목록으로 만든 다음에
// 매개변수 목록을 새로운 배열에 할당함
=======

*!*
let arrCopy = [...arr]; // spread the array into a list of parameters
// then put the result into a new array
let arrCopy = [...arr]; // 배열을 펼쳐서 각 요소를 분리후, 매개변수 목록으로 만든 다음에
// 매개변수 목록을 새로운 배열에 할당함
*/!*
>>>>>>> upstream/master

// 배열 복사본의 요소가 기존 배열 요소와 진짜 같을까요?
alert(JSON.stringify(arr) === JSON.stringify(arrCopy)); // true
Expand All @@ -268,16 +255,11 @@ alert(arrCopy); // 1, 2, 3

```js run
let obj = { a: 1, b: 2, c: 3 };
<<<<<<< HEAD
let objCopy = { ...obj }; // 객체를 펼쳐서 각 요소를 분리후, 매개변수 목록으로 만든 다음에
// 매개변수 목록을 새로운 객체에 할당함
=======

*!*
let objCopy = { ...obj }; // spread the object into a list of parameters
// then return the result in a new object
let objCopy = { ...obj }; // 객체를 펼쳐서 각 요소를 분리후, 매개변수 목록으로 만든 다음에
// 매개변수 목록을 새로운 객체에 할당함
*/!*
>>>>>>> upstream/master

// 객체 복사본의 프로퍼티들이 기존 객체의 프로퍼티들과 진짜 같을까요?
alert(JSON.stringify(obj) === JSON.stringify(objCopy)); // true
Expand All @@ -291,11 +273,7 @@ alert(JSON.stringify(obj)); // {"a":1,"b":2,"c":3,"d":4}
alert(JSON.stringify(objCopy)); // {"a":1,"b":2,"c":3}
```

<<<<<<< HEAD
이렇게 전개 구문을 사용하면 `let objCopy = Object.assign({}, obj);`, `let arrCopy = Object.assign([], arr);`보다 더 짧은 코드로 배열이나 객체를 복사할 수 있어서 사람들은 이 방법을 선호합니다.
=======
This way of copying an object is much shorter than `let objCopy = Object.assign({}, obj)` or for an array `let arrCopy = Object.assign([], arr)` so we prefer to use it whenever we can.
>>>>>>> upstream/master


## 요약
Expand Down