Better can only be defined in the context of your application. Usually, the public API you choose should reflect the use case of the application.
For that, let me present two different scenarios, in which for each of them I would give a different answer:
Scenario #1: capitalizing words is an user story
You are developing a text editing app, and there is a user story that says that the user can select words and capitalize them.
This is a scenario where
capitalizeWords is part of the user story and it makes sense for it to be part of the public API. In that case, I would say that:
- If selecting one word is just a special case of selecting N words (N=1), one could express this as just a function that receives a list.
- If there is a special case where the user can edit just one word, and that is semantically different from editing many words, expressing those as two different functions make a lot of sense.
Scenario #2: capitalizing words is just an implementation detail
You are developing a web app, and there is a search by keyword function. You are calling
capitalizeWord just as part of the requirement that the search should be case insensitive.
In that case,
capitalizeWord is a implementation detail and, as a result, not part of the public API. This means that it really does not matter for the user stories which one you choose, as long as the public API
searchByKeywords is working.
The only criteria for choosing to separate into more than one function would be so your code is cleaner.
In my opinion, the two options are both clean code (with the only exception that I would rename
capitalizeWordList, so the difference is more obvious).
Given that usually capitalizing words are not a user story, I would assume that you are working with Scenario Two.