20 lines
533 B
Text
20 lines
533 B
Text
class pair
|
|
function __construct(public name, public value) end
|
|
|
|
function __lt(other) return self.name < other.name end
|
|
|
|
function __tostring() return $"\{{self.name}, {self.value}}" end
|
|
end
|
|
|
|
local pairs = {
|
|
new pair("grass", "green"),
|
|
new pair("snow", "white"),
|
|
new pair("sky", "blue"),
|
|
new pair("cherry", "red")
|
|
}
|
|
|
|
print("Before sorting:")
|
|
print(" " .. pairs:mapped(|p| -> tostring(p)):concat("\n "))
|
|
pairs:sort()
|
|
print("\nAfter sorting:")
|
|
print(" " .. pairs:mapped(|p| -> tostring(p)):concat("\n "))
|