Skip to content

Instantly share code, notes, and snippets.

@cderv
Created July 27, 2023 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cderv/59e33962642001274829f3fe759c33ca to your computer and use it in GitHub Desktop.
Save cderv/59e33962642001274829f3fe759c33ca to your computer and use it in GitHub Desktop.
Sort Text file content in Typescript
import { readLines } from "https://deno.land/std@0.196.0/io/read_lines.ts";
const f= await Deno.open('tests/timing-for-ci.txt');
let counter = 0
const timedTests = [];
const timed = [];
let test: string;
let time: string;
for await (let line of readLines(f)) {
if (counter === 0) {
test = line
console.log(test)
counter = 1
} else if (counter === 1) {
time = line
counter = 2
}
if (counter === 2) {
timedTests.push({
test: test,
time: time
})
counter = 0
}
}
timedTests.sort((a, b) => {
const A = a.test;
const B = b.test;
return A.localeCompare(B);
});
const f= await Deno.open();
Deno.removeSync('tests/timing-for-ci.txt')
for (let test of timedTests) {
Deno.writeTextFileSync('tests/timing-for-ci.txt', `${test.test}\n`, { append: true})
Deno.writeTextFileSync('tests/timing-for-ci.txt', `${test.time}\n`, { append: true})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment