Skip to content

Commit f33efae

Browse files
committed
Add examples
1 parent 2354ef0 commit f33efae

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

JavaScript/1-array.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const arr = new Array(10);
4+
console.dir({ arr });
5+
6+
const even = [2, 4, 6, 8, 10, 12];
7+
console.dir({ even });
8+
9+
console.dir({
10+
length: even.length,
11+
first: even[0],
12+
last: even[even.length - 1]
13+
});
14+
15+
console.dir({
16+
'even.slice(1, 4)': even.slice(1, 4),
17+
'even.splice(2, 4, 3, 7, 9)': even.splice(2, 4, 3, 7, 9)
18+
});

JavaScript/2-hash.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const v8 = require('v8');
5+
6+
const SYMBOL_FILENAME = Symbol('fileName');
7+
8+
const hash1 = {
9+
key: 'value',
10+
[SYMBOL_FILENAME]: './file0.v8'
11+
};
12+
13+
hash1.key2 = 'value2';
14+
hash1['key' + 3] = 'value3';
15+
hash1[SYMBOL_FILENAME] = './file1.v8';
16+
hash1[SYMBOL_FILENAME] = './file2.v8';
17+
hash1[Symbol('fileName')] = './file3.v8';
18+
19+
console.log('FileName: ' + hash1[SYMBOL_FILENAME]);
20+
21+
for (const key in hash1) {
22+
const value = hash1[key];
23+
console.log({ key, value });
24+
}
25+
26+
console.dir({ keys: Object.keys(hash1) });
27+
console.dir({ hash1 });
28+
29+
const save = collection => fs.writeFile(
30+
collection[SYMBOL_FILENAME], v8.serialize(collection), () => {}
31+
);
32+
33+
save(hash1);

JavaScript/file2.v8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�o"key"value"key2"value2"key3"value3{

0 commit comments

Comments
 (0)