View Single Post
07/17/14, 12:08 PM   #5
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Argh, now I get what I did wrong:
The key was compared when value was bigger. Not only when it was equal. I Ultiamtively choose this version and it seems to work out:
Lua Code:
  1. local function CompareKeyValuePair(a, b)
  2.   --assert valid input
  3.   assert(type(a) == "table" and a.key ~= nil and a.value ~= nil, "argument a must be a table containing a 'key' and 'value' string-index")
  4.   assert(type(b) == "table" and b.key ~= nil and b.value ~= nil, "argument b must be a table containing a 'key' and 'value' string-index")
  5.  
  6.   --check if the value is smaller first
  7.   if (a.value < b.value) then
  8.     return true
  9.   end
  10.  
  11.   --if values are the same, try to order by key
  12.   if (a.value == b.value) and (a.key < b.key) then
  13.     return true
  14.   end
  15.  
  16.   return false
  17. end
Thanks for the help.
  Reply With Quote