Skip to content

Commit

Permalink
feat: reduce length of array.
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceWind committed Sep 8, 2024
1 parent 1da0867 commit 9d3cc02
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function main() {
console.log(`Current progress:`);

terminalBarUI.start(ips.length, 0);
const unsortedArr = [];
let unsortedArr = [];
for (let i = 0; i < ips.length; i++) {
const ip = ips[i];

Expand All @@ -125,13 +125,19 @@ async function main() {
unsortedArr.push({ ip, latency: avgLatency });
}
countOfBeingProcess--;
if (unsortedArr.length > 150) {
unsortedArr = unsortedArr.sort((a, b) => {
return a.latency - b.latency;
});
unsortedArr.slice(100, 150);
console.warn('removed 50 IPs.');
}
}
else {
countOfBeingProcess++;
queryAvgLatency(ip).then(function (avgLatency) {
if (avgLatency < THRESHOLD) {
unsortedArr.push({ ip, latency: avgLatency });
console.log(`Added ${ip} with latency ${avgLatency}`);
}
countOfBeingProcess--;
}).catch(function (e) {
Expand Down

0 comments on commit 9d3cc02

Please sign in to comment.