Skip to content

Instantly share code, notes, and snippets.

@omeroot
Last active October 20, 2015 13:32
Show Gist options
  • Save omeroot/dcafc6fc287b9945cca5 to your computer and use it in GitHub Desktop.
Save omeroot/dcafc6fc287b9945cca5 to your computer and use it in GitHub Desktop.
function swap(array, index1, index2) {
var temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
function WTFSorting(arr){
var res = [];
res.push(arr[0]);
console.log(res);
for(var i = 1 ;i < arr.length ; i++){
res.push(arr[i]);
console.log("before",res);
for(var j = 0 ; j< res.length - 1 ; j++){
if(arr[i] < res[j]){
this.swap(res, i, j);
console.log(res);
}
}
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment