Skip to content

Bucket:SortBy()

paige edited this page Aug 17, 2023 · 2 revisions
  • desc: sorts it but with another table/bucket
  • returns: Bucket: Table
  • args: Sort By: Table Optional Direction: Function
  • note: clones the original bucket
local bucket = Bucket.new({
    user1 = 5,
    user2 = 50,
    user3 = 10,
    user4 = 25
})

-- (( [ *user1 => 5 ], [ *user3 => 10 ], [ *user4 => 25 ], [ *user2 => 50 ] ))
bucket:SortBy(bucket:Values())


-- (( [ *user2 => 50 ], [ *user4 => 25 ], [ *user3 => 10 ], [ *user1 => 5 ] ))
bucket:SortBy(bucket:Values(), function(a, b)
    return b < a
end)

Clone this wiki locally