1
I’m trying to solve a problem, where I need to see the word more often in a String. The problem is that these words are assembled from a given size. For example:
"5tardenoitemanhãtardenoitetarde"
I would need to take the first number, which is the length of the words I need to search in the string that comes after that number, and return the word more often.
tarde
noite
manhã
tarde
noite
tarde
In that case it would be the word "late".
Would anyone have any idea how they could do, in the most "clean" way possible, plus have a check if there are no repeated words?
What have you tested?
– Sergio
It’s the trivial, it doesn’t have much to do, or move through the list of matching words or use regular expressions.
– Augusto Vasques
@Augustovasques is not so trivial :)
– Sergio
@Sergio trivial what I say is not to abbreviate the code using algorithms that generate shortcuts in similar problems with for example Ichtenstein distance to evaluate similarities between strings.
– Augusto Vasques
@Augustovasques I’m going to give an answer, I thought I could use a type regex
/(\d+)(\D{\1})+
but the capture group does not get what it was looking for. If you have another idea of a simpler answer, also put!– Sergio
@Sergio I’m just writing an answer, but it won’t come out much different than what you did.
– Augusto Vasques