This challenge is for all those times your mouth said something your brain didn't tell it to.
Write a function that will find a misspoken word in your speech
using the following words
:
are - aren't
can - can't
could - couldn't
did - didn't
do - don't
had - hadn't
has - hasn't
have - haven't
is - isn't
might - mightn't
must - mustn't
should - shouldn't
was - wasn't
were - weren't
would - wouldn't
Add or remove the suffix n't
where needed. Beware of the word "can" and extra suffixes like 've
.
speech
:
I do like pizza.
I haven't seen you wearing that hat before.
I could see why you would say that.
I didn't say it! It wasn't me!
YES, WE CAN
Good luck!
This challenge comes from dinglemouse on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (3)
Elm
Maybe not the best algorithm, show me yours!
Playground
Test it here.
What if the string is "Should I go?" or generally speaking when they come at the starting of a sentence?
You are right and this solution is not 100% bulletproof. Hence my little message just before saying that I'm curious about other answer.
What do you think we should do to resolve this issue?