Created
July 14, 2017 22:11
-
-
Save jaredatron/5fc861bd1fba0d803463e51903d75b62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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