Skip to content

Instantly share code, notes, and snippets.

@derekwyatt
Last active December 11, 2015 02:19
Show Gist options
  • Select an option

  • Save derekwyatt/4529947 to your computer and use it in GitHub Desktop.

Select an option

Save derekwyatt/4529947 to your computer and use it in GitHub Desktop.
% node -v
v0.6.12
% node
> [1,2,3,11,22].sort()
[ 1,
11,
2,
22,
3 ]
> console.log("That's just awesome")
damn right!
>
@petervenables
Copy link

now try: [1,2,3,11,22].sort(function(a,b){return a-b});

sort's default behaviour is to do an alphasort. Bash's sort will do the same thing:

cat << HERE | sort

1
2
3
11
22
HERE
1
11
2
22
3

@derekwyatt
Copy link
Author

Umm... yeah, but /usr/bin/sort isn't a programming language :) JS should probably understand the difference between [1,2,3,11,22] and ["1","2","3","11","22"].

@petervenables
Copy link

Fair point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment