-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson11spjo.js
40 lines (33 loc) · 1017 Bytes
/
lesson11spjo.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
var fs=require("fs");
var lst=fs.readFileSync("./lesson11spjo.lst","utf8").split(/\r?\n/);
var tomain=function(fn){
var text=fs.readFileSync("./"+fn+".txt","utf8").replace(/\n~1~/g,function(s){
return "~split~"+fn+"\n"+s;
}).split("~split~");
return text[0];
}
var toref=function(fn){
var text=fs.readFileSync("./"+fn+".txt","utf8").replace(/\n~1~/g,function(s){
return "~split~"+fn+"\n"+s;
}).split("~split~");
return text[1];
}
var rejoinedmain=lst.map(tomain).join("\n");
var rejoinedref=lst.map(toref).join("\n");
var group=0;
var numreplace=function(text){
return text.replace(/~(\d+)~/g,function(m,m1){
if (m1==="1") group++;
return "~"+group+"-"+m1+"~";
});
};
//fs.writeFileSync("./maintext.txt",numreplace(rejoinedmain),"utf8");
fs.writeFileSync("./reftext.txt",numreplace(rejoinedref),"utf8");
/*
var out=[rejoinedmain,rejoinedref];
var output=out.map(numreplace);
var outputfile=function(file,idx){
fs.writeFile("./lesson11spjo"+idx+".txt",file,"utf8");
}
output.map(outputfile);
*/