local array = { 13, 14, 52, 63, 764, 12342, 143, 2, 54, 63, 25, 15 } local sortedarray = { 0 } for ka, va in ipairs(array) do for j = 1, #sortedarray do if va > sortedarray[j] then if sortedarray[j] > 0 then for i = #sortedarray, j, -1 do sortedarray[i + 1] = sortedarray[i] end end sortedarray[j] = va end end end for k, v in ipairs(sortedarray) do print(k, v) end