Skip to content

Commit 848f719

Browse files
3-file-sort code
Signed-off-by: Arnav Gupta <[email protected]>
1 parent e5a630a commit 848f719

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

Lecture11/3-file-sort/out.txt

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
3+
4+
1
5+
2
6+
3
7+
3
8+
3
9+
4
10+
4
11+
4
12+
5
13+
5
14+
5
15+
6
16+
6
17+
7
18+
7
19+
8
20+
24
21+
24
22+
26
23+
34
24+
34
25+
35
26+
35
27+
35
28+
42
29+
43
30+
46
31+
46
32+
46
33+
52
34+
52
35+
52
36+
52
37+
52
38+
53
39+
56
40+
56
41+
57
42+
57
43+
58
44+
67
45+
68
46+
69
47+
73
48+
78
49+
86
50+
234
51+
234
52+
237
53+
243
54+
245
55+
245
56+
245
57+
245
58+
245
59+
324
60+
357
61+
357
62+
425
63+
457
64+
462
65+
524
66+
524
67+
524
68+
532
69+
563
70+
567
71+
573
72+
624
73+
624
74+
624
75+
656
76+
735
77+
875
78+
876
79+
2346
80+
2354
81+
3245
82+
4224
83+
4624
84+
6245
85+
7987
86+
9857
87+
32345
88+
56345
89+
56746
90+
56756
91+
56789
92+
456785

Lecture11/3-file-sort/sort.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fs = require('fs')
2+
const os = require('os')
3+
os.EOL // instead of '\n'
4+
5+
let arr = []
6+
fs.readFile(__dirname + '/1.txt', (err, data) => {
7+
arr = arr.concat(data.toString().split(os.EOL))
8+
9+
fs.readFile(__dirname + '/2.txt', (err, data) => {
10+
arr = arr.concat(data.toString().split(os.EOL))
11+
12+
fs.readFile(__dirname + '/3.txt', (err, data) => {
13+
arr = arr.concat(data.toString().split(os.EOL))
14+
15+
arr = arr.sort((a, b) => a - b)
16+
17+
fs.writeFile(__dirname + '/out.txt', arr.join(os.EOL), (err) => {
18+
19+
console.log('Done')
20+
})
21+
})
22+
})
23+
})

0 commit comments

Comments
 (0)