拆分出数组中的奇数和偶数
--将某个数组分成两个数组,一个存放偶数,一个存放奇数
local t = {4,2,3,4,1,6,5,7,8,45,9}
function device(array)
local oushArr = {}
local jishArr = {}
for i=1,#array do
if t[i]%2 == 0 then
oushArr[#oushArr + 1] = array[i]
else
jishArr[#jishArr + 1] = array[i]
end
end
return oushArr,jishArr
end
local a,b = device(t)
for k,v in pairs(a) do
print(k,v)
end
for k,v in pairs(b) do
print(k,v)
end
local t = {4,2,3,4,1,6,5,7,8,45,9}
function device(array)
local oushArr = {}
local jishArr = {}
for i=1,#array do
if t[i]%2 == 0 then
oushArr[#oushArr + 1] = array[i]
else
jishArr[#jishArr + 1] = array[i]
end
end
return oushArr,jishArr
end
local a,b = device(t)
for k,v in pairs(a) do
print(k,v)
end
for k,v in pairs(b) do
print(k,v)
end