Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Created July 14, 2017 22:11
Show Gist options
  • Save jaredatron/5fc861bd1fba0d803463e51903d75b62 to your computer and use it in GitHub Desktop.
Save jaredatron/5fc861bd1fba0d803463e51903d75b62 to your computer and use it in GitHub Desktop.
const numbers = [5,2,4,3,1]
const sorterA = (a,b) => {
if (a < b) return -1
if (b < a) return 1
return 0
}
const sorterB = (a,b) => {
if (a < b) return 1
if (b < a) return -1
return 0
}
const sorterC = (a,b) => {
return -1
}
const sorterD = (a,b) => {
return 1
}
const sorterE = (a,b) => {
return 0
}
const sorterF = (a,b) => {
return a - b
}
const sorterG = (a,b) => {
return b - a
}
console.log("\nsorterA:\n", sorterA.toString(), '\nYIELDS', numbers.sort(sorterA))
console.log("\nsorterB:\n", sorterB.toString(), '\nYIELDS', numbers.sort(sorterB))
console.log("\nsorterC:\n", sorterC.toString(), '\nYIELDS', numbers.sort(sorterC))
console.log("\nsorterD:\n", sorterD.toString(), '\nYIELDS', numbers.sort(sorterD))
console.log("\nsorterE:\n", sorterE.toString(), '\nYIELDS', numbers.sort(sorterE))
console.log("\nsorterF:\n", sorterF.toString(), '\nYIELDS', numbers.sort(sorterF))
console.log("\nsorterG:\n", sorterG.toString(), '\nYIELDS', numbers.sort(sorterG))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment