Sampling Unique Coords

Benchmark created on


Setup

const coords = [
{
  "activity_type": "unknown",
  "activity_confidence": 100,
  "battery_level": -1,
  "battery_is_charging": false,
  "extras": {},
  "mock": true,
  "is_moving": false,
  "age": 305,
  "odometer": 2752.7,
  "uuid": "54F81B7F-B2E6-4BCA-8FBE-9B41BB9C5CFC",
  "event": "motionchange",
  "timestamp": "2024-07-08T14:39:09.842Z",
  "speed_accuracy": 0,
  "speed": 3.39,
  "longitude": -122.02501579,
  "ellipsoidal_altitude": 0,
  "floor": 0,
  "heading_accuracy": 0,
  "latitude": 37.33020628,
  "accuracy": 10,
  "altitude_accuracy": -1,
  "altitude": 0,
  "heading": 86.08,
  "id": 442,
  "recorded_at": "2024-07-08T14:39:09.842Z",
  "created_at": "2024-07-08T14:39:10.174Z",
  "company_id": null,
  "device_id": null
},
{
  "activity_type": "unknown",
  "activity_confidence": 100,
  "battery_level": -1,
  "battery_is_charging": false,
  "extras": {},
  "mock": true,
  "is_moving": false,
  "age": 305,
  "odometer": 2752.7,
  "uuid": "54F81B7F-B2E6-4BCA-8FBE-9B41BB9C5CFC",
  "event": "motionchange",
  "timestamp": "2024-07-08T14:39:09.842Z",
  "speed_accuracy": 0,
  "speed": 3.39,
  "longitude": -122.02501579,
  "ellipsoidal_altitude": 0,
  "floor": 0,
  "heading_accuracy": 0,
  "latitude": 37.33020628,
  "accuracy": 10,
  "altitude_accuracy": -1,
  "altitude": 0,
  "heading": 86.08,
  "id": 442,
  "recorded_at": "2024-07-08T14:39:09.842Z",
  "created_at": "2024-07-08T14:39:10.174Z",
  "company_id": null,
  "device_id": null
},{
  "activity_type": "unknown",
  "activity_confidence": 100,
  "battery_level": -1,
  "battery_is_charging": false,
  "extras": {},
  "mock": true,
  "is_moving": true,
  "age": 4,
  "odometer": 2718.5,
  "uuid": "16F074AF-7182-4243-A759-F36EB2C911B1",
  "timestamp": "2024-07-08T14:38:25.855Z",
  "speed_accuracy": 0,
  "speed": 3.98,
  "longitude": -122.02700675,
  "ellipsoidal_altitude": 0,
  "floor": 0,
  "heading_accuracy": 0,
  "latitude": 37.33023066,
  "accuracy": 10,
  "altitude_accuracy": -1,
  "altitude": 0,
  "heading": 93.19,
  "id": 434,
  "recorded_at": "2024-07-08T14:38:25.855Z",
  "created_at": "2024-07-08T14:38:25.891Z",
  "company_id": null,
  "device_id": null
}]

Test runner

Ready to run.

Testing in
TestOps/sec
Reduce & Filter
const uniqueCoords = coords => {
  const uniqueIdSet = coords.reduce(
    (acc, coord) => acc.add(`${coord.latitude},${coord.longitude}`),
    new Set(),
  );

  return coords.filter(c => uniqueIdSet.has(c.uuid));
};
ready
Filter & Set
const uniqueCoords = (coords) => {
                    const uniqueSet = new Set()
                    return coords.filter(coord => {
                        const key = `${coord.latitude},${coord.longitude}`
                        if (uniqueSet.has(key)) {
                            return false
                        }
                        uniqueSet.add(key)
                        return true
                    })
                }
                
uniqueCoords(coords)
ready

Revisions

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