(points, left, right)
| 151 | }; |
| 152 | |
| 153 | var partition = function (points, left, right) { |
| 154 | let pivot = choosePivot(points, left, right); |
| 155 | let pivotDist = squaredDistance(pivot); |
| 156 | while (left < right) { |
| 157 | // Iterate through the range and swap elements to make sure |
| 158 | // that all points closer than the pivot are to the left |
| 159 | if (squaredDistance(points[left]) >= pivotDist) { |
| 160 | [points[left], points[right]] = [points[right], points[left]]; |
| 161 | right--; |
| 162 | } else { |
| 163 | left++; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Ensure the left pointer is just past the end of |
| 168 | // the left range then return it as the new pivotIndex |
| 169 | if (squaredDistance(points[left]) < pivotDist) { |
| 170 | left++; |
| 171 | } |
| 172 | |
| 173 | return left; |
| 174 | }; |
| 175 | |
| 176 | // Choose a pivot element of the array |
| 177 | const choosePivot = (points, left, right) => |
no test coverage detected