Created
January 8, 2020 21:48
-
-
Save NickHeiner/a6e96c86831023e8689bc931fae2acd9 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
const arr = [ | |
{id: 'a', val: 0}, | |
{id: 'b', val: 1}, | |
{id: 'c', val: 1}, | |
{id: 'd', val: 1}, | |
{id: 'e', val: 1}, | |
{id: 'f', val: 1}, | |
{id: 'g', val: 1}, | |
{id: 'h', val: 1}, | |
{id: 'i', val: 1}, | |
{id: 'j', val: 1}, | |
{id: 'k', val: 1}, | |
{id: 'l', val: 1}, | |
{id: 'm', val: 1}, | |
{id: 'n', val: 1}, | |
{id: 'o', val: 1}, | |
{id: 'p', val: 2}, | |
]; | |
console.log(process.versions.node) | |
console.log(arr.sort(({val: valA}, {val: valB}) => { | |
if (valA === valB) { | |
return 0; | |
} | |
if (valA > valB) { | |
return 1; | |
} | |
return -1; | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment