diff options
| author | Teddy Wing | 2015-10-08 05:03:12 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-10-08 05:03:12 -0400 |
| commit | 9a50e8f4abe9f50b7640b55afb606db6d3d4b0a8 (patch) | |
| tree | 12266e8001ea7cc9ceea475bd70c27a09e1bb46c /autoload | |
| parent | a9d0c154661dd7c07c00bf74bfbf79858a8a042d (diff) | |
| download | vim-space-vlaze-9a50e8f4abe9f50b7640b55afb606db6d3d4b0a8.tar.bz2 | |
leaderboard#Sort: Convert inputs to numbers before comparing
Otherwise the inputs get compared as strings and only the leftmost digit
of the number gets sorted so you end up with things like this:
[8, 43, 2, 13, 0]
Convert our inputs to numbers so that they get compared in their
entirety and larger numbers move to the head of the list.
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/space_vlaze/leaderboard.vim | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/autoload/space_vlaze/leaderboard.vim b/autoload/space_vlaze/leaderboard.vim index 155b537..4eabb7c 100644 --- a/autoload/space_vlaze/leaderboard.vim +++ b/autoload/space_vlaze/leaderboard.vim @@ -34,8 +34,11 @@ endfunction " Sorting function that orders numbers from highest to lowest. " For use with the |sort()| Vim function function! space_vlaze#leaderboard#Sort(item1, item2) - return a:item1 ==# a:item2 ? 0 : - \ a:item1 ># a:item2 ? -1 : 1 + let item1 = str2nr(a:item1) + let item2 = str2nr(a:item2) + + return item1 ==# item2 ? 0 : + \ item1 ># item2 ? -1 : 1 endfunction |
