Move map and push.apply to a for loop
Remove usage of map from array input
Remove unnecessary keys check
Use function declaration for consistency