Detect duplicate coordinates in ring

Benchmark created on


Setup

const ring = []
for (var i=0; i<10000; i++) ring.push([i, i])
const equal = (A, B) => A[0] === B[0] && A[1] === B[1]

Test runner

Ready to run.

Testing in
TestOps/sec
Array some
return ring.some((A, i) => ring.slice(i + 1).some((B) => equal(A, B)))
ready
Nested for loops
for (var i=0; i<ring.length; i++) {
	for (var j=i+1; j<ring.length; j++) {
		if (equal(ring[i], ring[j])) return true
	}
}
return false
ready
Set of strings
const s = new Set(ring.map(c => `${c[0]}|${c[1]}`))
return s.size === ring.length
ready
Set of strings (destructure)
const s = new Set(ring.map(([lon, lat]) => `${lon}|${lat}`))
return s.size === ring.length
ready
Set of strings (join)
const s = new Set(ring.map(c => c.join('|')))
return s.size === ring.length
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.