"optimizating by returning the value of array from function f and declaring localy the array in event function