Last active
April 15, 2019 19:36
-
-
Save jfolds/de17d5b49fbade942d54ee306701257b to your computer and use it in GitHub Desktop.
This file contains 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
function sortData(data, column, direction) { | |
const sortedData = data.sort((a, b) => { | |
let val1 = a[column]; | |
let val2 = b[column]; | |
val1 = typeof val1 === 'string' ? val1.toUpperCase() : val1; | |
val2 = typeof val2 === 'string' ? val2.toUpperCase() : val2; | |
return (val1 < val2) | |
? -1 | |
: 1 | |
? (val1 > val2) | |
: 1 | |
? -1 | |
: 0; | |
}); | |
if (direction === 'desc') { | |
sortedData.reverse(); | |
} | |
return sortedData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment