example of swap sorting fucntion c++
Example: minimum number of swaps to sort an array javascript
function minimumSwaps(arr) {
let swap = 0
for(let i = 0;i<arr.length;i++) {
while(arr[i] !== i+1) {
let temp = arr[i]
arr[i] = arr[temp - 1]
arr[temp - 1] = temp
swap++;
}
}
return swap
}