How to iterate through the end of an array?

Suppose we have an array of 1’s and 0’s with a span of 7 elements long. I need to iterate at the end of that array. How? I tried setting its index to -1 but it keeps returning only 1 iteration.

local function computeFitness(chromosome)
	local chromosomeArray = string.split(chromosome, "")
	local bitValue = 0
	for i=1, #chromosomeArray, -1 do --Iterate from the end of the byte
		bitValue += tonumber(chromosomeArray[i])^2
		print(i)
	end
	return bitValue
end
1 Like
for i = #chromosomeArray, 1, -1 do
3 Likes