(nums, index = 0)
| 149 | }; |
| 150 | |
| 151 | const cyclicSort = (nums, index = 0) => { |
| 152 | const swap = (arr, a, b) => ([arr[a], arr[b]] = [arr[b], arr[a]]); |
| 153 | |
| 154 | while (index < nums.length) { |
| 155 | /* Time O(N) */ |
| 156 | const [num, arrayIndex, arrayNum] = [ |
| 157 | nums[index], |
| 158 | nums[index] - 1, |
| 159 | nums[nums[index] - 1], |
| 160 | ]; |
| 161 | |
| 162 | const canSwap = !isSame(num, arrayNum); |
| 163 | if (canSwap) { |
| 164 | swap(nums, index, arrayIndex); |
| 165 | |
| 166 | continue; |
| 167 | } |
| 168 | |
| 169 | index++; |
| 170 | } |
| 171 | }; |
| 172 | const isSame = (a, b) => a === b; |
| 173 | |
| 174 | const search = (nums) => { |
no test coverage detected