Skip to content

Commit 48f92b0

Browse files
committed
Improve old examples
1 parent c3456de commit 48f92b0

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

JavaScript/4-boxing.js

Lines 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

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy