(points, k)
| 10 | * @return {number[][]} |
| 11 | */ |
| 12 | var kClosest = function (points, k) { |
| 13 | // Sort the array with a custom lambda comparator function |
| 14 | points.sort((a, b) => squaredDistance(a) - squaredDistance(b)); |
| 15 | |
| 16 | // Return the first k elements of the sorted array |
| 17 | return points.slice(0, k); |
| 18 | }; |
| 19 | |
| 20 | // Calculate and return the squared Euclidean distance |
| 21 | const squaredDistance = ([x, y]) => x ** 2 + y ** 2; |
nothing calls this directly
no test coverage detected