Semrush Interview Question

How would you refactor this big function?