Semrush interview question

How would you refactor this big function?