Skip to content

Todo-list server and sorting wala assignment #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Assignment-sorting-1/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
20984375
2345
3245
2345
234
5234
5234
532
45324
5
32423
4632
57
26
38
38
2436348
5
3509687
20 changes: 20 additions & 0 deletions Assignment-sorting-1/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
130587243
234609872356
532067
1
1
2
452
326
3255
7
456
8768
967
7
362
46
4578
357
32
5
20 changes: 20 additions & 0 deletions Assignment-sorting-1/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
345987
2346
236
3457
246
547
2
109782078
203946872059876
340587
23457
3546
7
5478
22
11
313
12342345
23534567679
92685
58 changes: 58 additions & 0 deletions Assignment-sorting-1/Assig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const fs = require("fs/promises");

let array = [];
/* const readIt = () => {
for (let j = 1; j <= 3; j++) {
fs.readFileSync(`${j}.txt`, (err, data) => {
arr = data.toString().split("\n");
for (let i = 0; i < arr.length; i++) {
array.push(Number(arr[i]));
// console.log(Number(arr[i]));
}
});
}
};
readIt(); */
// import fs from "fs/promises";
const sortNumber = (a, b) => {
if (a > b) {
return 1;
} else if (b > a) {
return -1;
} else {
return 0;
}
};

const readIt = async () => {
let file1 = await fs.readFile("1.txt");
let file2 = await fs.readFile("2.txt");
let file3 = await fs.readFile("3.txt");
file1 = file1.toString().split("\n");
file2 = file2.toString().split("\n");
file3 = file3.toString().split("\n");
// console.log("1: ", file1, "\n 2: ", file2, "\n 3: ", file3);
for (let i = 0; i < file1.length; i++) {
array.push(Number(file1[i]));
}
for (let i = 0; i < file2.length; i++) {
array.push(Number(file2[i]));
}
for (let i = 0; i < file3.length; i++) {
array.push(Number(file3[i]));
}
// array = [...file1, ...file2, ...file3];
array.sort(sortNumber);
let ans = "";
for (let i = 0; i < array.length; i++) {
ans += array[i].toString() + "\n";
}

fs.writeFile("solution.txt", ans, (err) => {
if (err) throw err;
else {
console.log("File saved! ");
}
});
};
readIt();
59 changes: 59 additions & 0 deletions Assignment-sorting-1/solution.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
1
1
2
2
5
5
5
7
7
7
11
22
26
32
38
38
46
57
234
236
246
313
326
357
362
452
456
532
547
967
2345
2345
2346
3245
3255
3457
3546
4578
4632
5234
5234
5478
8768
23457
32423
45324
92685
340587
345987
532067
2436348
3509687
12342345
20984375
109782078
130587243
23534567679
234609872356
203946872059876
Loading