-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice.js
58 lines (50 loc) · 1.33 KB
/
practice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const fs = require("fs");
const csvReadStream = fs.createReadStream("input.csv", { encoding: "utf-8" });
let arrow = "-->";
let result = "";
let dataTempStore = "";
csvReadStream.on("data", (data) => {
for (let i = 0; i < data.length; i++) {
if (data[i] === ":" || data[i] === ",") {
result = result + dataTempStore + ",";
dataTempStore = "";
} else {
dataTempStore = dataTempStore + data[i];
}
}
result = result + dataTempStore;
dataTempStore = "";
for (let i = 0; i < result.length; i++) {
if (result[i] !== " ") {
dataTempStore = dataTempStore + result[i];
}
}
result = dataTempStore;
dataTempStore = "";
let array = [];
let count = 0;
for (let i = 0; i < result.length; i++) {
if (result[i] === '"' || result[i] === ",") {
if (result[i] === '"') {
count++;
if (count === 2) {
array.push(dataTempStore);
dataTempStore = "";
count = 0;
}
}
} else {
dataTempStore = dataTempStore + result[i];
}
}
result = "";
let obj = {};
for (let i = 0; i < array.length; i = i + 2) {
obj[array[i]] = array[i + 1];
}
console.log(obj);
// for (let i = 0; i < array.length; i = i + 2) {
// result = result + `${array[i]} ` + arrow + ` ${array[i + 1]}\n`;
// }
// console.log(result);
});