Skip to content

Commit

Permalink
improve array sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
maaaathis committed Feb 8, 2024
1 parent 2b20916 commit e8c3c52
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions app/lookup/[domain]/map/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,23 @@ const MapResultsPage: FC<MapResultsPageProps> = async ({
</Link>
));

let hasDifferentRecords = false;
for (let i = 1; i < markers.length; i++) {
const previous = markers[i - 1].results;
const current = markers[i].results;
if (
previous.A.toSorted().toString() !== current.A.toSorted().toString() ||
previous.AAAA.toSorted().toString() !==
current.AAAA.toSorted().toString() ||
previous.CNAME.toSorted().toString() !==
current.CNAME.toSorted().toString()
) {
hasDifferentRecords = true;
break;
}
}
const hasDifferentRecords = markers.some((marker, index) => {
if (index === 0) return false;

const previous = markers[index - 1].results;
const current = marker.results;

const compareRecords = (recordType: 'A' | 'AAAA' | 'CNAME') => {
return (
previous[recordType].length !== current[recordType].length ||
previous[recordType].some((ip, idx) => ip !== current[recordType][idx])
);
};

return (
compareRecords('A') || compareRecords('AAAA') || compareRecords('CNAME')
);
});

return (
<>
Expand Down

0 comments on commit e8c3c52

Please sign in to comment.