Created
August 31, 2026 16:20
-
-
Save prettydiff/fe1456dbd458b8a376961f4f658c76d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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