Last active
February 20, 2019 13:23
-
-
Save yuriitaran/5492d69283aab137810c0baa2fd5c9fa to your computer and use it in GitHub Desktop.
Javascript sorting
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
// sort array of objects by items value ('jobId') | |
data.sort((a, b) => { | |
if (a.jobId > b.jobId) { | |
return -1 | |
} else if (a.jobId < b.jobId) { | |
return 1 | |
} else { | |
return 0 | |
} | |
}) | |
// sort array without changing it | |
function arSort(array) { | |
array = array.map(item => item).sort(); | |
return array; | |
} | |
function arSort(array) { | |
array = [...array].sort(); | |
return array; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment