Skip to content

Instantly share code, notes, and snippets.

@ctavan
Created March 11, 2019 21:24
Show Gist options
  • Save ctavan/e3efa8dc61c3759987ffad5fdc5cdd24 to your computer and use it in GitHub Desktop.
Save ctavan/e3efa8dc61c3759987ffad5fdc5cdd24 to your computer and use it in GitHub Desktop.
Array Sort Behavior Node 10 and 11
const unsorted1 = [1, 0, 0, 1];
console.log(process.version, [...unsorted1], '->', unsorted1.sort(( value ) => value));
const unsorted2 = [1, -1, -1, 1];
console.log(process.version, [...unsorted2], '->', unsorted2.sort(( value ) => value));
v8.15.1 [ 1, 0, 0, 1 ] -> [ 0, 0, 1, 1 ]
v10.15.2 [ 1, 0, 0, 1 ] -> [ 0, 0, 1, 1 ]
v11.9.0 [ 1, 0, 0, 1 ] -> [ 1, 0, 0, 1 ] // <----- OUCH!
v8.15.1 [ 1, -1, -1, 1 ] -> [ -1, -1, 1, 1 ]
v10.15.2 [ 1, -1, -1, 1 ] -> [ -1, -1, 1, 1 ]
v11.9.0 [ 1, -1, -1, 1 ] -> [ -1, -1, 1, 1 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment