The reason why three functions are called (and in the same order), because you call them when called, when you put them in an array.
It:
let randomFunc = [self.firstFunction(), self.secondFunction(), self.thirdFunction()]
Stores the return value of each function in an array as you call them (by adding ` ()
`).
So, at this point, the randomFunc
return values are contained, not the function closures
Instead, just save the functions themselves:
[self.firstFunction, self.secondFunction, self.thirdFunction]
, , , :
//return randomFunc[randomResult] // This will return the function closure
randomFunc[randomResult]() // This will execute the selected function