Skip to content

Instantly share code, notes, and snippets.

@prettydiff
Created August 31, 2026 16:20
Show Gist options
  • Select an option

  • Save prettydiff/fe1456dbd458b8a376961f4f658c76d5 to your computer and use it in GitHub Desktop.

Select an option

Save prettydiff/fe1456dbd458b8a376961f4f658c76d5 to your computer and use it in GitHub Desktop.
import fs from "node:fs";
(function (){
const start=process.hrtime.bigint();
// add the absolute file path to a local copy of dats_dates.txt
fs.readFile("file_path.txt", function(err, file){
if (err === null) {
const lines=file.toString("utf8").split("\n"),
len=lines.length,
output_raw={},
output=[];
let index = len,
key="",
keys=[];
do {
index = index - 1;
key = lines[index].split("_")[0];
if (output_raw[key] === undefined) {
output_raw[key] = 1;
} else {
output_raw[key] = output_raw[key] + 1;
}
} while (index > 0);
keys = Object.keys(output_raw);
keys.sort(function(a,b){
if (output_raw[a] < output_raw[b]) {
return - 1;
}
return 1;
});
index = keys.length;
do {
index = index - 1;
output.push([keys[index], output_raw[keys[index]]]);
} while (index > 0);
// put absolute output file path here
fs.writeFile("file_path.txt",JSON.stringify(output).replace(/\],/g, "],\n"),function(erw){
if (erw === null) {
console.log(`Operation completed in ${Number(process.hrtime.bigint() - start) / 1e9} seconds.`);
} else {
console.log(erw);
}
});
} else {
console.log(err);
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment