You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An array, just like an object, may end with a comma:
101
+
배열은 객체와 마찬가지로 마지막 요소 끝에 콤마를 붙여줄 수 있습니다.
91
102
```js
92
103
let fruits = [
93
104
"Apple",
@@ -97,56 +108,77 @@ let fruits = [
97
108
```
98
109
99
110
The "trailing comma" style makes it easier to insert/remove items, because all lines become alike.
111
+
트레일링 콤마 스타일은 가시성을 높여 아이템 추가 혹은 삭제를 더욱 편리하게 해줍니다.
100
112
````
101
113
102
114
103
115
## Methods pop/push, shift/unshift
104
116
105
117
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))는 배열의 가장 흔한 쓰임새 중 하나입니다. 컴퓨터 과학에서 큐는 다음과 같은 두 개의 동작이 가능한 순서가 있는 요소들의 컬렉션입니다.
106
119
107
120
-`push` appends an element to the end.
121
+
-`push` 끝에 요소를 추가합니다.
108
122
-`shift` get an element from the beginning, advancing the queue, so that the 2nd element becomes the 1st.
123
+
-`shift` 맨 앞에 있는 요소를 가져오고, 2번째 요소가 1번째 요소가 되도록 합니다.
124
+
109
125
110
126

111
127
112
128
Arrays support both operations.
129
+
배열은 두 가지 동작이 모두 가능합니다.
113
130
114
131
In practice we meet it very often. For example, a queue of messages that need to be shown on-screen.
132
+
연습문제에서 우리는 큐를 자주 보게 될 것입니다. 예를 들어 스크린에 보여져야 할 메세지의 큐 같은 것 말입니다.
115
133
116
134
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
+
117
137
118
138
It supports two operations:
139
+
스택은 두 가지 동작이 가능합니다.
119
140
120
141
-`push` adds an element to the end.
142
+
-`push`는 끝에 요소를 추가합니다.
121
143
-`pop` takes an element from the end.
144
+
-`pop`은 끝에서 요소를 꺼내옵니다.
122
145
123
146
So new elements are added or taken always from the "end".
147
+
즉 새로운 요소들은 항상 "끝"에 추가되며, 기존 요소들은 항상 "끝"에서 꺼내집니다.
124
148
125
149
A stack is usually illustrated as a pack of cards: new cards are added to the top or taken from the top:
150
+
스택은 보통 카드뭉치로 비유됩니다: 새로운 카드들은 위쪽에 올리고, 기존 카드들은 위에서부터 가져옵니다.
126
151
127
152

128
153
129
154
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)이라고 합니다.
130
157
131
158
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
+
자바스크립트의 배열은 스택으로도, 큐로도 작동할 수 있습니다. 가장 처음 혹은 맨 끝에서 요소를 추가/삭제하는 것이 가능하기 때문입니다.
132
160
133
161
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)라고 합니다.
134
163
135
164
**Methods that work with the end of the array:**
165
+
**배열의 끝에서 동작하는 메소드들**
136
166
137
167
`pop`
138
168
: Extracts the last element of the array and returns it:
169
+
: 배열의 마지막 요소를 추출하여 리턴합니다:
139
170
140
171
```js run
141
172
let fruits = ["Apple", "Orange", "Pear"];
142
173
143
-
alert( fruits.pop() ); // remove "Pear" and alert it
174
+
alert( fruits.pop() ); // remove "Pear" and alert it "Pear"을 삭제하고 alert합니다.
144
175
145
176
alert( fruits ); // Apple, Orange
146
177
```
147
178
148
179
`push`
149
180
: Append the element to the end of the array:
181
+
: 배열의 끝에 요소를 추가합니다:
150
182
151
183
```js run
152
184
let fruits = ["Apple", "Orange"];
@@ -157,22 +189,26 @@ In computer science the data structure that allows it is called [deque](https://
157
189
```
158
190
159
191
The call `fruits.push(...)` is equal to `fruits[fruits.length] = ...`.
192
+
`fruits.push(...)`와 `fruits[fruits.length] = ...`의 결과는 동일합니다.
160
193
161
194
**Methods that work with the beginning of the array:**
195
+
**배열의 시작 부분에서 작동하는 메소드들**
162
196
163
197
`shift`
164
198
: Extracts the first element of the array and returns it:
199
+
: 배열의 가장 처음 요소를 빼낸 뒤 리턴합니다:
165
200
166
201
```js
167
202
let fruits = ["Apple", "Orange", "Pear"];
168
203
169
-
alert( fruits.shift() ); // remove Apple and alert it
204
+
alert( fruits.shift() ); // Apple을 제거한 뒤 alert합니다
170
205
171
206
alert( fruits ); // Orange, Pear
172
207
```
173
208
174
209
`unshift`
175
210
: Add the element to the beginning of the array:
211
+
: 배열의 시작 부분에 요소를 추가합니다:
176
212
177
213
```js
178
214
let fruits = ["Orange", "Pear"];
@@ -183,6 +219,7 @@ In computer science the data structure that allows it is called [deque](https://
183
219
```
184
220
185
221
Methods `push` and `unshift` can add multiple elements at once:
222
+
`push`와 `unshift` 메소드는 여러 개의 요소를 한번에 더할 수 있습니다:
186
223
187
224
```js run
188
225
let fruits = ["Apple"];
@@ -195,28 +232,34 @@ alert( fruits );
195
232
```
196
233
197
234
## Internals
235
+
## 인터널
198
236
199
237
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로 사용되지요.
200
239
201
240
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` 프로퍼티를 사용할 수 있지만, 본질적으로 배열은 객체입니다.
202
242
203
243
Remember, there are only 7 basic types in JavaScript. Array is an object and thus behaves like an object.
244
+
자바스크립트에는 7개의 기본 타입이 있다는 것을 기억하세요. 배열은 객체이며 따라서 객체처럼 행동합니다.
204
245
205
246
For instance, it is copied by reference:
247
+
예를 들어, 배열은 by reference로 복사됩니다:
206
248
207
249
```js run
208
250
let fruits = ["Banana"]
209
251
210
-
let arr = fruits; // copy by reference (two variables reference the same array)
252
+
let arr = fruits; // copy by reference (두 변수가 동일한 배열을 참조)
211
253
212
254
alert( arr === fruits ); // true
213
255
214
-
arr.push("Pear"); //modify the array by reference
256
+
arr.push("Pear"); //by reference로 배열을 수정
215
257
216
-
alert( fruits ); // Banana, Pear - 2 items now
258
+
alert( fruits ); // Banana, Pear - 이제 요소가 2개입니다.
217
259
```
218
260
219
261
...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
+
...하지만 배열을 정말 특별하게 만드는 것은 인터널 표현입니다.(?) 이 챕터의 그림들에서 배열의 요소들이 순차적으로 나열된 모습으로 묘사되었듯이, 엔진은 배열의 요소들을 메모리 상에 연속적으로 저장하려고 시도합니다. 물론 배열이 매우 빨리 작동하게끔 하는 다른 최적화들도 있습니다.
220
263
221
264
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.
0 commit comments