Skip to content

Instantly share code, notes, and snippets.

@zambony
Last active March 1, 2020 22:22
Show Gist options
  • Save zambony/12d1cd8569e28e5d23322b75a0cb62e6 to your computer and use it in GitHub Desktop.
Save zambony/12d1cd8569e28e5d23322b75a0cb62e6 to your computer and use it in GitHub Desktop.
-- Convenience function to explode some text
local function explode(str, separator)
local out = {}
for w in str:gmatch("([^" .. separator .. "]+)") do out[#out + 1] = w end
return out
end
function table.swap(t, a, b)
t[a], t[b] = t[b], t[a]
end
local defaultComp = function(a, b) return a > b end
function table.insertionsort(t, comp)
comp = comp or defaultComp
for i = 2, #t do
local j = i
while (j > 1 and comp(t[j - 1], t[j])) do
table.swap(t, j, j - 1)
j = j - 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment