← Back to challenges

A Subtle Switcheroo

JavaScriptHardstringsregex

Instructions

Create a function which replaces all instances of "nts" with "nce" and vice versa if they are at the end of a word.

Examples

switcheroo("The elephants in France were chased by ants!") ➞ "The elephance in Frants were chased by ance!"

switcheroo("While he rants, I fall into a trance...") ➞ "While he rance, I fall into a trants..."

switcheroo("Bounced over the fence!") ➞ "Bounced over the fents!"

Notes

  • Empty strings should return just an empty string (see example #2).
  • Ignore punctuation and any instances where "nts" or "nce" are not at the end of a word (see example #3).
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.