First, we use a regular expression to separate the first consonants, the remaining word and subsequent non-word-characters in each word of any sentence (the latter being useful so we don't have to take care about word boundaries - but it can be left away if you only want to translate single words).
Then we use the replace method with a callback to recombine these matches to the intended result using a template string. We need the callback to ensure that words not starting with a consonant will end in 'way'.
I am a Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g
Here's what I would have come up with:
First, we use a regular expression to separate the first consonants, the remaining word and subsequent non-word-characters in each word of any sentence (the latter being useful so we don't have to take care about word boundaries - but it can be left away if you only want to translate single words).
Then we use the replace method with a callback to recombine these matches to the intended result using a template string. We need the callback to ensure that words not starting with a consonant will end in 'way'.
Alex, thank you for this solution. I love the simplicity and I am definitely checking it out 👏🏼