8000 Improve examples · HowProgrammingWorks/Factory@56314ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 56314ae

Browse files
committed
Improve examples
1 parent 36696d8 commit 56314ae

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

JavaScript/4-function.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const logger = (level = 'info') => {
1515
};
1616

1717
const warning = logger('warning');
18-
warning('Hello');
18+
warning('Hello warning');
19+
20+
const error = logger('error');
21+
error('Hello error');
1922

2023
const info = logger('info');
21-
info('Hello error');
24+
info('Hello info');

JavaScript/6-factorify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class Person {
77
}
88

99
const factorify =
10-
(Category) =>
10+
(Entity) =>
1111
(...args) =>
12-
new Category(...args);
12+
new Entity(...args);
1313

1414
// Usage
1515

JavaScript/7-pool.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
const POOL_SIZE = 1000;
44

55
const pool = (factory) => {
6-
const instance = factory();
7-
const items = new Array(POOL_SIZE).fill(instance);
6+
const items = new Array(POOL_SIZE).fill(null).map(() => factory());
87
return (item) => {
98
let res = null;
109
if (item) {
@@ -21,9 +20,9 @@ const pool = (factory) => {
2120
// Usage
2221

2322
const factory = () => new Array(1000).fill(0);
24-
const arrays = pool(factory);
23+
const arrayPool = pool(factory);
2524

26-
const a1 = arrays();
25+
const a1 = arrayPool();
2726
const b1 = a1.map((x, i) => i).reduce((x, y) => x + y);
2827
console.log(b1);
2928

0 commit comments

Comments
 (0)
0