From 9a50e8f4abe9f50b7640b55afb606db6d3d4b0a8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 8 Oct 2015 05:03:12 -0400 Subject: 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. --- autoload/space_vlaze/leaderboard.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'autoload') 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 -- cgit v1.2.3