Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active May 30, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/ee95a7e72f3c758d6544eab054ce2697 to your computer and use it in GitHub Desktop.
Save mcsee/ee95a7e72f3c758d6544eab054ce2697 to your computer and use it in GitHub Desktop.
sortFunction = function(arr, fn) {
var len = arr.length;
for (var i = 0; i < len ; i++) {
for(var j = 0 ; j < len - i - 1; j++) {
if (fn(arr[j], arr[ j+ 1])) {
var temp = arr[j];
arr[j] = arr[j+1];
arr[j + 1] = temp;
}
}
}
return arr;
}
scores = [9, 5, 2, 7, 23, 1, 3];
sorted = sortFunction(scores, (a,b) => {return a > b});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment