-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
47 lines (36 loc) · 995 Bytes
/
index.ts
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
import fs from 'node:fs'
function getNetworkSaves() {
fs.readFile('./network.txt', 'utf8', (err, data) => {
const networks = JSON.parse(data)
interface Nodos {
[key: string]: number[]
}
const nodos: Nodos = {}
let result = ''
for (let i = 0; i < networks.length; i++) {
const nodo = networks[i]
nodo.forEach((n: number) => {
if (n in nodos) {
nodos[n] = [...nodos[n], i]
} else {
nodos[n] = [i]
}
})
}
const indicesToRemove = new Set<number>()
for (const key in nodos) {
if (nodos[key].length > 1) {
nodos[key].forEach(i => {
indicesToRemove.add(i)
})
}
}
const indicesToRemoveSorted = [...indicesToRemove].sort((a, b) => b - a)
indicesToRemoveSorted.forEach(index => {
networks.splice(index, 1)
})
result = networks.map((n: number[]) => n.join(',')).join(',')
console.log({ result })
})
}
getNetworkSaves()