aboutsummaryrefslogtreecommitdiffstats
path: root/autoload
diff options
context:
space:
mode:
authorTeddy Wing2015-10-08 05:03:12 -0400
committerTeddy Wing2015-10-08 05:03:12 -0400
commit9a50e8f4abe9f50b7640b55afb606db6d3d4b0a8 (patch)
tree12266e8001ea7cc9ceea475bd70c27a09e1bb46c /autoload
parenta9d0c154661dd7c07c00bf74bfbf79858a8a042d (diff)
downloadvim-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.vim7
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