You are viewing a single comment's thread. Return to all comments →
this was super helpful! but you have some typos. fixes here:
var origArray = arr.slice(0); var sortedArray = arr.sort((a,b) => a - b); for(var i = 0; i < origArray.length; i++) { if (origArray[i] != sortedArray[i]) { for (var j = i+1; j < origArray.length; j++) { if(origArray[j] === sortedArray[i]) { swap(origArray[i],origArray[j]) numberOfSwap++ break; } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
this was super helpful! but you have some typos. fixes here: