I am having a table in which I am passing names:
names = {'Sachin', 'Ponting', 'Dhoni'}
and in other table I am passing country names:
country = {"India", "Australia", "India"}
I want output table like:
out_table = {Sachin="India", Ponting="Australia", Dhoni="India"}
Here's a straight-forward attempt:
names = {'Sachin', 'Ponting', 'Dhoni'}
countries = {"India", "Australia", "India"}
function table_map(names, countries)
local out = {}
for i, each in ipairs(names) do
out[each] = countries[i]
end
return out
end
out_table = table_map(names, countries)
Live repl demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With