Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48f92b0

Browse filesBrowse files
committed
Improve old examples
1 parent c3456de commit 48f92b0
Copy full SHA for 48f92b0

File tree

Expand file treeCollapse file tree

3 files changed

+20
-11
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+20
-11
lines changed

‎JavaScript/4-boxing.js

Copy file name to clipboardExpand all lines: JavaScript/4-boxing.js
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
'use strict';
22

33
class ArrayToQueueAdapter {
4-
constructor(arr) {
5-
this.array = arr;
4+
#array = null;
5+
6+
constructor(array) {
7+
if (!Array.isArray(array)) {
8+
throw new Error('Array instance expected');
9+
}
10+
this.#array = array;
611
}
712

813
enqueue(data) {
9-
this.array.push(data);
14+
this.#array.push(data);
1015
}
1116

1217
dequeue() {
13-
return this.array.pop();
18+
return this.#array.pop();
1419
}
1520

1621
get count() {
17-
return this.array.length;
22+
return this.#array.length;
1823
}
1924
}
2025

‎JavaScript/5-closure.js

Copy file name to clipboardExpand all lines: JavaScript/5-closure.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
'use strict';
22

3-
const arrayToQueueAdapter = (arr) => ({
3+
const arrayToQueueAdapter = (array) => ({
44
enqueue(data) {
5-
arr.push(data);
5+
array.push(data);
66
},
77

88
dequeue() {
9-
return arr.pop();
9+
return array.pop();
1010
},
1111

1212
get count() {
13-
return arr.length;
13+
return array.length;
1414
}
1515
});
1616

‎JavaScript/6-interface.js

Copy file name to clipboardExpand all lines: JavaScript/6-interface.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ class HashMap {
1010
}
1111

1212
set(key, value) {
13-
this.fs.writeFileSync(this.path + key, JSON.stringify(value), 'utf8');
13+
const name = this.path + key;
14+
const data = JSON.stringify(value);
15+
this.fs.writeFileSync(name, data, 'utf8');
1416
}
1517

1618
get(key) {
17-
return JSON.parse(this.fs.readFileSync(this.path + key, 'utf8'));
19+
const name = this.path + key;
20+
const data = this.fs.readFileSync(name, 'utf8');
21+
return JSON.parse(data);
1822
}
1923

2024
has(key) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.