Refactoring to Rework the Logic
Sometimes when refactoring to the functional style, we may have to step back and rethink the logic or the algorithm instead of merely trying to map from the imperative to functional style. If we don’t take an alternative approach in such cases, either we may have issues creating functional style code or the refactored version may be complex and leave us wanting for a better solution. We’ll look at one such problem in this section—this was raised by a developer who was interested in solving this problem and was having a hard time creating a functional equivalent.
Given a string, we want to find the first letter that’s repeated anywhere else in the string. For example, in the string hellothere, the first letter ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access