From e8c3c52cd7a676fabcf3744a1d5dd576594e2ceb Mon Sep 17 00:00:00 2001 From: Mathis Date: Thu, 8 Feb 2024 23:09:39 +0100 Subject: [PATCH] improve array sorting --- app/lookup/[domain]/map/page.tsx | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/lookup/[domain]/map/page.tsx b/app/lookup/[domain]/map/page.tsx index db80e8a0..b007d805 100644 --- a/app/lookup/[domain]/map/page.tsx +++ b/app/lookup/[domain]/map/page.tsx @@ -89,21 +89,23 @@ const MapResultsPage: FC = async ({ )); - 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 ( <>