DEV Community

Discussion on: Daily Challenge #39 - Virus

Collapse
 
alvaromontoro profile image
Alvaro Montoro • Edited

JavaScript

const normalize = string => string.toLowerCase()
                                  .replace(/ie/g, "ei")
                                  .split('. ')
                                  .map(val => val[0].toUpperCase() + val.substring(1))
                                  .join('. ');

But this solution has the same problem that La battle mentions in another comment: if a word contains a valid "ie" string, it will be transformed into "ei" incorrectly. I was testing the sentence He haD iEght ShOTs of CAffIEne. thEn hE dIeD and the last "dIeD" was being transformed into "deid". One option could be extending the function to check a dictionary or make a call to an API to verify the word is valid, but that could be a pain too.

Another possible extension would be to split not only by ., but also by other sentence delimiters such as ? or !.

Collapse
 
anwar_nairi profile image
Anwar • Edited

Also, if your sentence contains nouns such as He haD iEght ShOTs of CAffIEne in Paris. thEn hE dIeD, you will loose the upper P of Paris.