Pregunta de entrevista de Semrush

How would you refactor this big function?