Skip to content

Commit 220ddc7

Browse files
[배열] 과제 번역
1 parent 4110e84 commit 220ddc7

File tree

9 files changed

+64
-65
lines changed

9 files changed

+64
-65
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
The result is `4`:
1+
정답은 `4`입니다.
22

33

44
```js run
5-
let fruits = ["Apples", "Pear", "Orange"];
5+
let fruits = ["사과", "", "오렌지"];
66

77
let shoppingCart = fruits;
88

9-
shoppingCart.push("Banana");
9+
shoppingCart.push("바나나");
1010

1111
*!*
1212
alert( fruits.length ); // 4
1313
*/!*
1414
```
1515

16-
That's because arrays are objects. So both `shoppingCart` and `fruits` are the references to the same array.
17-
16+
배열은 객체이기 때문에 `shoppingCart``fruits`는 모두 같은 배열을 참조합니다.

1-js/05-data-types/04-array/1-item-value/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 3
22

33
---
44

5-
# Is array copied?
5+
# 배열은 복사가 될까요?
66

7-
What is this code going to show?
7+
아래 코드를 실행하면 어떤 결과가 나올까요?
88

99
```js
10-
let fruits = ["Apples", "Pear", "Orange"];
10+
let fruits = ["사과", "", "오렌지"];
1111

12-
// push a new value into the "copy"
12+
// 배열을 '복사'한 후, push 메서드를 이용해 새로운 값을 추가합니다.
1313
let shoppingCart = fruits;
14-
shoppingCart.push("Banana");
14+
shoppingCart.push("바나나");
1515

16-
// what's in fruits?
16+
// fruits에 어떤 값이 들어 있을까요?
1717
alert( fruits.length ); // ?
1818
```
1919

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
# Slow solution
1+
# 느린 해답
22

3-
We can calculate all possible subsums.
3+
만들 수 있는 모든 부분 배열의 합을 계산하는 방법이 있을 수 있습니다.
44

5-
The simplest way is to take every element and calculate sums of all subarrays starting from it.
5+
이를 구현하는 가장 간단한 방법은 배열의 각 요소를 시작으로 하는 모든 부분 배열의 합을 계산하는 것입니다.
66

7-
For instance, for `[-1, 2, 3, -9, 11]`:
7+
예를 들어 배열 `[-1, 2, 3, -9, 11]`이 있다고 합시다.
88

99
```js no-beautify
10-
// Starting from -1:
10+
// -1부터 시작
1111
-1
1212
-1 + 2
1313
-1 + 2 + 3
1414
-1 + 2 + 3 + (-9)
1515
-1 + 2 + 3 + (-9) + 11
1616

17-
// Starting from 2:
17+
// 2부터 시작
1818
2
1919
2 + 3
2020
2 + 3 + (-9)
2121
2 + 3 + (-9) + 11
2222

23-
// Starting from 3:
23+
// 3부터 시작
2424
3
2525
3 + (-9)
2626
3 + (-9) + 11
2727

28-
// Starting from -9
28+
// -9부터 시작
2929
-9
3030
-9 + 11
3131

32-
// Starting from 11
32+
// 11부터 시작
3333
11
3434
```
3535

36-
The code is actually a nested loop: the external loop over array elements, and the internal counts subsums starting with the current element.
36+
위와 같은 알고리즘을 사용하려면 중첩 반복문이 필요합니다. 외부 반복문에선 배열의 각 요소를 순회하고, 내부 반복문에선 각 요소부터 시작하는 부분 배열의 합을 계산하게 됩니다.
3737

3838
```js run
3939
function getMaxSubSum(arr) {
40-
let maxSum = 0; // if we take no elements, zero will be returned
40+
let maxSum = 0; // 어떤 요소도 선택하지 않으면 0을 반환합니다.
4141

4242
for (let i = 0; i < arr.length; i++) {
4343
let sumFixedStart = 0;
@@ -57,25 +57,25 @@ alert( getMaxSubSum([1, 2, 3]) ); // 6
5757
alert( getMaxSubSum([100, -9, 2, -3, 5]) ); // 100
5858
```
5959

60-
The solution has a time complexety of [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation). In other words, if we increase the array size 2 times, the algorithm will work 4 times longer.
60+
이렇게 구현하면 시간 복잡도가 [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation)이 됩니다. 이는 배열의 크기를 2배 늘리면 알고리즘은 4배나 더 오래 걸린다는 의미입니다.
6161

62-
For big arrays (1000, 10000 or more items) such algorithms can lead to a serious sluggishness.
62+
크기가 큰 배열(1000, 10000 또는 그 이상의 요소를 가진 배열)에 위와 같은 알고리즘을 적용하면 매우 느릴 수 있습니다.
6363

64-
# Fast solution
64+
# 빠른 해답
6565

66-
Let's walk the array and keep the current partial sum of elements in the variable `s`. If `s` becomes negative at some point, then assign `s=0`. The maximum of all such `s` will be the answer.
66+
배열을 순회하면서 변수 `s`에 현재의 부분합을 저장하는 방법도 가능합니다. `s`가 음수가 된 경우는 `s``0`을 할당하면 됩니다. `s`의 값 중 최댓값이 정답이 됩니다.
6767

68-
If the description is too vague, please see the code, it's short enough:
68+
해설이 모호하다고 느껴지면 아래 코드를 참고해주세요.
6969

7070
```js run demo
7171
function getMaxSubSum(arr) {
7272
let maxSum = 0;
7373
let partialSum = 0;
7474

75-
for (let item of arr) { // for each item of arr
76-
partialSum += item; // add it to partialSum
77-
maxSum = Math.max(maxSum, partialSum); // remember the maximum
78-
if (partialSum < 0) partialSum = 0; // zero if negative
75+
for (let item of arr) { // 배열의 각 요소를
76+
partialSum += item; // partialSum에 더합니다.
77+
maxSum = Math.max(maxSum, partialSum); // 최대값을 기억해 놓습니다.
78+
if (partialSum < 0) partialSum = 0; // 음수가 되면 0을 대입합니다.
7979
}
8080

8181
return maxSum;
@@ -89,6 +89,6 @@ alert( getMaxSubSum([1, 2, 3]) ); // 6
8989
alert( getMaxSubSum([-1, -2, -3]) ); // 0
9090
```
9191

92-
The algorithm requires exactly 1 array pass, so the time complexity is O(n).
92+
이 알고리즘은 정확히 한번 배열을 순회하므로 시간 복잡도는 O(n)입니다.
9393

94-
You can find more detail information about the algorithm here: [Maximum subarray problem](http://en.wikipedia.org/wiki/Maximum_subarray_problem). If it's still not obvious why that works, then please trace the algorithm on the examples above, see how it works, that's better than any words.
94+
알고리즘에 대한 상세한 정보는 [최대합 부분 배열 문제](http://en.wikipedia.org/wiki/Maximum_subarray_problem)에서 찾을 수 있습니다. 동작원리에 대해 확실히 이해가 되지 않았다면 위 예제의 알고리즘이 어떻게 동작하는지 찬찬히 살펴보세요. 그릉ㄹ 읽는 것보다 코드를 살펴보는게 훨씬 도움이 될 겁니다.

1-js/05-data-types/04-array/10-maximal-subarray/task.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ importance: 2
22

33
---
44

5-
# A maximal subarray
5+
# 최대합 부분 배열
66

7-
The input is an array of numbers, e.g. `arr = [1, -2, 3, 4, -9, 6]`.
7+
입력값은 `arr = [1, -2, 3, 4, -9, 6]` 같이 숫자로만 구성된 배열이라고 가정해봅시다.
88

9-
The task is: find the contiguous subarray of `arr` with the maximal sum of items.
9+
우리가 해야 할 일은 요소의 총합이 최대인 `arr`의 부분 배열을 찾는 것입니다.
1010

11-
Write the function `getMaxSubSum(arr)` that will return that sum.
11+
부분 배열 요소들의 합을 리턴하는 함수 `getMaxSubSum(arr)`를 작성해 봅시다.
1212

13-
For instance:
13+
예시:
1414

1515
```js
16-
getMaxSubSum([-1, *!*2, 3*/!*, -9]) == 5 (the sum of highlighted items)
16+
getMaxSubSum([-1, *!*2, 3*/!*, -9]) == 5 (강조 표시된 요소들의 합)
1717
getMaxSubSum([*!*2, -1, 2, 3*/!*, -9]) == 6
1818
getMaxSubSum([-1, 2, 3, -9, *!*11*/!*]) == 11
1919
getMaxSubSum([-2, -1, *!*1, 2*/!*]) == 3
2020
getMaxSubSum([*!*100*/!*, -9, 2, -3, 5]) == 100
21-
getMaxSubSum([*!*1, 2, 3*/!*]) == 6 (take all)
21+
getMaxSubSum([*!*1, 2, 3*/!*]) == 6 (모든 요소)
2222
```
2323

24-
If all items are negative, it means that we take none (the subarray is empty), so the sum is zero:
24+
요소 전체가 음수라면 아무런 요소도 선택하지 않아야 최댓값이 됩니다(부분 배열은 빈 배열). 그리고 합은 0이 됩니다.
2525

2626
```js
2727
getMaxSubSum([-1, -2, -3]) = 0
2828
```
2929

30-
Please try to think of a fast solution: [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation) or even O(n) if you can.
30+
가능하다면 성능을 고려하여 답안을 작성해 봅시다. 답안은 [O(n<sup>2</sup>)](https://en.wikipedia.org/wiki/Big_O_notation) 또는 O(n)까지 가능합니다.

1-js/05-data-types/04-array/2-create-array/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 5
22

33
---
44

5-
# Array operations.
5+
# 배열과 관련된 연산
66

7-
Let's try 5 array operations.
7+
배열과 관련된 다섯 가지 연산을 해봅시다.
88

9-
1. Create an array `styles` with items "Jazz" and "Blues".
10-
2. Append "Rock-n-Roll" to the end.
11-
3. Replace the value in the middle by "Classics". Your code for finding the middle value should work for any arrays with odd length.
12-
4. Strip off the first value of the array and show it.
13-
5. Prepend `Rap` and `Reggae` to the array.
9+
1. 요소 "Jazz", "Blues"가 있는 `styles` 배열을 생성합니다.
10+
2. "Rock-n-Roll"을 배열 끝에 추가합니다.
11+
3. 배열 정 중앙에 있는 요소를 "Classics"로 바꿉니다. 가운데 요소를 찾는 코드는 요소가 홀수 개인 배열에서도 잘 작동해야 합니다.
12+
4. 배열의 첫 번째 요소를 꺼내서 출력합니다.
13+
5. "Rap"과 "Reggae"를 배열의 앞에 추가합니다.
1414

15-
The array in the process:
15+
단계를 하나씩 거칠 때마다 배열 모습은 아래와 같이 변해야 합니다.
1616

1717
```js no-beautify
1818
Jazz, Blues
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The call `arr[2]()` is syntactically the good old `obj[method]()`, in the role of `obj` we have `arr`, and in the role of `method` we have `2`.
1+
`arr[2]()`를 호출하는 것은 `obj``arr`이고, `method``2`인 메서드 `obj[method]()`를 호출하는 것과 문법적으로 동일합니다.
22

3-
So we have a call of the function `arr[2]` as an object method. Naturally, it receives `this` referencing the object `arr` and outputs the array:
3+
즉, `arr[2]`에 있는 함수가 객체 메서드처럼 호출되는 것이죠. 따라서 `arr[2]``arr`을 참조하는 `this`를 받고, 배열을 출력합니다.
44

55
```js run
66
let arr = ["a", "b"];
@@ -9,7 +9,7 @@ arr.push(function() {
99
alert( this );
1010
})
1111

12-
arr[2](); // "a","b",function
12+
arr[2](); // a,b,function(){...}
1313
```
1414

15-
The array has 3 values: initially it had two, plus the function.
15+
배열은 초기 2개의 값에 함수가 추가되어 총 3개의 값을 가집니다.

1-js/05-data-types/04-array/3-call-array-this/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Calling in an array context
5+
# 배열 컨텍스트에서 함수 호출하기
66

7-
What is the result? Why?
7+
아래 코드를 실행하면 어떤 결과가 나올까요? 그리고 그 이유는 무엇일까요?
88

99
```js
1010
let arr = ["a", "b"];

1-js/05-data-types/04-array/5-array-input-sum/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Please note the subtle, but important detail of the solution. We don't convert `value` to number instantly after `prompt`, because after `value = +value` we would not be able to tell an empty string (stop sign) from the zero (valid number). We do it later instead.
1+
해답에서 작지만 중요한 역할을 하는 부분에 주의를 기울여 주세요. `+value`로 입력받은 값을 숫자형으로 변경한 이후엔, 빈 문자열(정지 신호)을 0(유효한 숫자)과 구분할 수 없기 때문에, `prompt` 직후에 `value`를 숫자로 변환하지 않고 나중에 숫자로 변환하였습니다.
22

33

44
```js run demo
@@ -8,9 +8,9 @@ function sumInput() {
88

99
while (true) {
1010

11-
let value = prompt("A number please?", 0);
11+
let value = prompt("숫자를 입력해 주세요.", 0);
1212

13-
// should we cancel?
13+
// 입력받는 것을 정지해야 하는 경우
1414
if (value === "" || value === null || !isFinite(value)) break;
1515

1616
numbers.push(+value);

1-js/05-data-types/04-array/5-array-input-sum/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ importance: 4
22

33
---
44

5-
# Sum input numbers
5+
# 입력한 숫자의 합 구하기
66

7-
Write the function `sumInput()` that:
7+
아래 조건을 만족하는 함수 `sumInput()`을 작성해 봅시다.
88

9-
- Asks the user for values using `prompt` and stores the values in the array.
10-
- Finishes asking when the user enters a non-numeric value, an empty string, or presses "Cancel".
11-
- Calculates and returns the sum of array items.
9+
- `prompt` 창을 띄워 사용자에게 숫자를 입력해 달라고 요청한 후, 입력받은 값들을 배열에 저장합니다.
10+
- 숫자가 아닌 값, 혹은 빈 문자열을 입력하거나 'Cancel' 버튼을 누르면 질문을 멈춥니다.
11+
- 배열 요소의 합을 계산하고 리턴합니다.
1212

13-
P.S. A zero `0` is a valid number, please don't stop the input on zero.
13+
주의: 숫자 `0`은 유효한 숫자이므로, 사용자가 `0`을 입력하더라도 질문이 멈추지 말아야 합니다.
1414

1515
[demo]

0 commit comments

Comments
 (0)