close
Skip to content

Commit b126f85

Browse files
committed
translate till half of internals
1 parent a57f5a4 commit b126f85

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

‎1-js/05-data-types/04-array/article.md‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ There exists a special data structure named `Array`, to store ordered collection
1818
## Declaration
1919

2020
There are two syntaxes for creating an empty array:
21+
빈 배열을 만드는 방법은 두 가지가 있습니다.
2122

2223
```js
2324
let arr = new Array();
2425
let arr = [];
2526
```
2627

2728
Almost all the time, the second syntax is used. We can supply initial elements in the brackets:
29+
거의 모든 경우에 두 번째 방법이 사용됩니다. 각괄호 안에 요소들을 넣어 선언할 수도 있습니다.
2830

2931
```js
3032
let fruits = ["Apple", "Orange", "Plum"];
3133
```
3234

3335
Array elements are numbered, starting with zero.
36+
배열 요소들은 0부터 순서가 매겨집니다.
3437

3538
We can get an element by its number in square brackets:
39+
각괄호 안에 요소의 순서를 넣어 요소의 값을 얻을 수 있습니다.
3640

3741
```js run
3842
let fruits = ["Apple", "Orange", "Plum"];
@@ -43,18 +47,21 @@ alert( fruits[2] ); // Plum
4347
```
4448

4549
We can replace an element:
50+
요소를 교체할 수도 있습니다.
4651

4752
```js
4853
fruits[2] = 'Pear'; // now ["Apple", "Orange", "Pear"]
4954
```
5055

5156
...Or add a new one to the array:
57+
또는 배열에 새 요소를 추가할 수도 있습니다.
5258

5359
```js
5460
fruits[3] = 'Lemon'; // now ["Apple", "Orange", "Pear", "Lemon"]
5561
```
5662

5763
The total count of the elements in the array is its `length`:
64+
배열에 들어있는 요소의 총 개수는 요소의 `length`입니다.
5865

5966
```js run
6067
let fruits = ["Apple", "Orange", "Plum"];
@@ -63,6 +70,7 @@ alert( fruits.length ); // 3
6370
```
6471

6572
We can also use `alert` to show the whole array.
73+
또한 `alert`를 사용해 전체 배열을 볼 수 있습니다.
6674

6775
```js run
6876
let fruits = ["Apple", "Orange", "Plum"];
@@ -71,8 +79,10 @@ alert( fruits ); // Apple,Orange,Plum
7179
```
7280

7381
An array can store elements of any type.
82+
하나의 배열에 어떤 종류의 요소라도 저장할 수 있습니다.
7483

7584
For instance:
85+
예를 들면 아래와 같습니다:
7686

7787
```js run no-beautify
7888
// mix of values
@@ -88,6 +98,7 @@ arr[3](); // hello
8898

8999
````smart header="Trailing comma"
90100
An array, just like an object, may end with a comma:
101+
배열은 객체와 마찬가지로 마지막 요소 끝에 콤마를 붙여줄 수 있습니다.
91102
```js
92103
let fruits = [
93104
"Apple",
@@ -97,56 +108,77 @@ let fruits = [
97108
```
98109
99110
The "trailing comma" style makes it easier to insert/remove items, because all lines become alike.
111+
트레일링 콤마 스타일은 가시성을 높여 아이템 추가 혹은 삭제를 더욱 편리하게 해줍니다.
100112
````
101113

102114

103115
## Methods pop/push, shift/unshift
104116

105117
A [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is one of most common uses of an array. In computer science, this means an ordered collection of elements which supports two operations:
118+
[](https://en.wikipedia.org/wiki/Queue_(abstract_data_type))는 배열의 가장 흔한 쓰임새 중 하나입니다. 컴퓨터 과학에서 큐는 다음과 같은 두 개의 동작이 가능한 순서가 있는 요소들의 컬렉션입니다.
106119

107120
- `push` appends an element to the end.
121+
- `push` 끝에 요소를 추가합니다.
108122
- `shift` get an element from the beginning, advancing the queue, so that the 2nd element becomes the 1st.
123+
- `shift` 맨 앞에 있는 요소를 가져오고, 2번째 요소가 1번째 요소가 되도록 합니다.
124+
109125

110126
![](queue.png)
111127

112128
Arrays support both operations.
129+
배열은 두 가지 동작이 모두 가능합니다.
113130

114131
In practice we meet it very often. For example, a queue of messages that need to be shown on-screen.
132+
연습문제에서 우리는 큐를 자주 보게 될 것입니다. 예를 들어 스크린에 보여져야 할 메세지의 큐 같은 것 말입니다.
115133

116134
There's another use case for arrays -- the data structure named [stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)).
135+
배열의 또다른 활용 예시도 있습니다. [스택](https://en.wikipedia.org/wiki/Stack_(abstract_data_type))이라는 자료구조입니다.
136+
117137

118138
It supports two operations:
139+
스택은 두 가지 동작이 가능합니다.
119140

120141
- `push` adds an element to the end.
142+
- `push`는 끝에 요소를 추가합니다.
121143
- `pop` takes an element from the end.
144+
- `pop`은 끝에서 요소를 꺼내옵니다.
122145

123146
So new elements are added or taken always from the "end".
147+
즉 새로운 요소들은 항상 "끝"에 추가되며, 기존 요소들은 항상 "끝"에서 꺼내집니다.
124148

125149
A stack is usually illustrated as a pack of cards: new cards are added to the top or taken from the top:
150+
스택은 보통 카드뭉치로 비유됩니다: 새로운 카드들은 위쪽에 올리고, 기존 카드들은 위에서부터 가져옵니다.
126151

127152
![](stack.png)
128153

129154
For stacks, the latest pushed item is received first, that's also called LIFO (Last-In-First-Out) principle. For queues, we have FIFO (First-In-First-Out).
155+
스택에서는 가장 최근에 추가된 요소를 먼저 받습니다. 이는 LIFO (후입선출, Last-In-First-Out)라고도 합니다.
156+
큐의 경우는 FIFO(선입선출, First-In-First-Out)이라고 합니다.
130157

131158
Arrays in JavaScript can work both as a queue and as a stack. They allow you to add/remove elements both to/from the beginning or the end.
159+
자바스크립트의 배열은 스택으로도, 큐로도 작동할 수 있습니다. 가장 처음 혹은 맨 끝에서 요소를 추가/삭제하는 것이 가능하기 때문입니다.
132160

133161
In computer science the data structure that allows it is called [deque](https://en.wikipedia.org/wiki/Double-ended_queue).
162+
컴퓨터 과학에서 그러한 동작이 가능한 자료구조를 [deque](https://en.wikipedia.org/wiki/Double-ended_queue)라고 합니다.
134163

135164
**Methods that work with the end of the array:**
165+
**배열의 끝에서 동작하는 메소드들**
136166

137167
`pop`
138168
: Extracts the last element of the array and returns it:
169+
: 배열의 마지막 요소를 추출하여 리턴합니다:
139170

140171
```js run
141172
let fruits = ["Apple", "Orange", "Pear"];
142173

143-
alert( fruits.pop() ); // remove "Pear" and alert it
174+
alert( fruits.pop() ); // remove "Pear" and alert it "Pear"을 삭제하고 alert합니다.
144175

145176
alert( fruits ); // Apple, Orange
146177
```
147178

148179
`push`
149180
: Append the element to the end of the array:
181+
: 배열의 끝에 요소를 추가합니다:
150182

151183
```js run
152184
let fruits = ["Apple", "Orange"];
@@ -157,22 +189,26 @@ In computer science the data structure that allows it is called [deque](https://
157189
```
158190

159191
The call `fruits.push(...)` is equal to `fruits[fruits.length] = ...`.
192+
`fruits.push(...)`와 `fruits[fruits.length] = ...`의 결과는 동일합니다.
160193

161194
**Methods that work with the beginning of the array:**
195+
**배열의 시작 부분에서 작동하는 메소드들**
162196

163197
`shift`
164198
: Extracts the first element of the array and returns it:
199+
: 배열의 가장 처음 요소를 빼낸 뒤 리턴합니다:
165200

166201
```js
167202
let fruits = ["Apple", "Orange", "Pear"];
168203

169-
alert( fruits.shift() ); // remove Apple and alert it
204+
alert( fruits.shift() ); // Apple을 제거한 뒤 alert합니다
170205

171206
alert( fruits ); // Orange, Pear
172207
```
173208

174209
`unshift`
175210
: Add the element to the beginning of the array:
211+
: 배열의 시작 부분에 요소를 추가합니다:
176212

177213
```js
178214
let fruits = ["Orange", "Pear"];
@@ -183,6 +219,7 @@ In computer science the data structure that allows it is called [deque](https://
183219
```
184220

185221
Methods `push` and `unshift` can add multiple elements at once:
222+
`push``unshift` 메소드는 여러 개의 요소를 한번에 더할 수 있습니다:
186223

187224
```js run
188225
let fruits = ["Apple"];
@@ -195,28 +232,34 @@ alert( fruits );
195232
```
196233

197234
## Internals
235+
## 인터널
198236

199237
An array is a special kind of object. The square brackets used to access a property `arr[0]` actually come from the object syntax. Numbers are used as keys.
238+
배열은 특별한 종류의 객체입니다. 요소값에 접근하기 위한 각괄호는 객체 문법에서 유래한 것입니다. 숫자가 key로 사용되지요.
200239

201240
They extend objects providing special methods to work with ordered collections of data and also the `length` property. But at the core it's still an object.
241+
순서가 있는 데이터 컬렉션을 다루기 위한 특별한 메소드들과 `lenght` 프로퍼티를 사용할 수 있지만, 본질적으로 배열은 객체입니다.
202242

203243
Remember, there are only 7 basic types in JavaScript. Array is an object and thus behaves like an object.
244+
자바스크립트에는 7개의 기본 타입이 있다는 것을 기억하세요. 배열은 객체이며 따라서 객체처럼 행동합니다.
204245

205246
For instance, it is copied by reference:
247+
예를 들어, 배열은 by reference로 복사됩니다:
206248

207249
```js run
208250
let fruits = ["Banana"]
209251

210-
let arr = fruits; // copy by reference (two variables reference the same array)
252+
let arr = fruits; // copy by reference (두 변수가 동일한 배열을 참조)
211253

212254
alert( arr === fruits ); // true
213255

214-
arr.push("Pear"); // modify the array by reference
256+
arr.push("Pear"); // by reference로 배열을 수정
215257

216-
alert( fruits ); // Banana, Pear - 2 items now
258+
alert( fruits ); // Banana, Pear - 이제 요소가 2개입니다.
217259
```
218260

219261
...But what makes arrays really special is their internal representation. The engine tries to store its elements in the contiguous memory area, one after another, just as depicted on the illustrations in this chapter, and there are other optimizations as well, to make arrays work really fast.
262+
...하지만 배열을 정말 특별하게 만드는 것은 인터널 표현입니다.(?) 이 챕터의 그림들에서 배열의 요소들이 순차적으로 나열된 모습으로 묘사되었듯이, 엔진은 배열의 요소들을 메모리 상에 연속적으로 저장하려고 시도합니다. 물론 배열이 매우 빨리 작동하게끔 하는 다른 최적화들도 있습니다.
220263

221264
But they all break if we quit working with an array as with an "ordered collection" and start working with it as if it were a regular object.
222265

0 commit comments

Comments
 (0)