Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.