An internet meme from 2003 (read more here) asserted that readers are relatively insensitive to letter order in words, so long as the first and last letters are unchanged.
Given a string of words s, take each word in turn and reverse the order of letters 2 through n-1, where n is the length of the words. Non-alphabetic characters should remain in place.
So if
sIn = 'hello'
then
sOut = 'hlleo'
And if
sIn = 'This is the first time I have used MATLAB.'
then
sOut = 'Tihs is the fsrit tmie I hvae uesd MALTAB.'
Put more test cases in. Makes cheating too tempting.
the regexp solution is great
Adding a test case containing words with hyphens like 'hard-working' will make this problem more challenging.
Test 1 doesn't work, I literally have the same result and it fails, but test 2 passes
Your function produces sOut in string format (in the last line of the function). The test suite defines the variables as character arrays instead of strings. These two data types cannot be directly compared—i.e., you'll have to return a character array.
Also, when I run your function, it returns "hello" rather than "hlleo".
I've tried the assert in MATLAB on my desktop and it doesn't throw an error... so I'm not really sure where it's gone wrong here. I'm guessing it's something tiny I've missed. Any help?
Which version of MATLAB are you using on your desktop? I tried running your solution on MATLAB desktop version 2019a and the solution is failing with correct assertions. In order to figure out the version of MATLAB, command "ver' will get you the version.
The version of matlab is not going to affect the result. This solution removes punctuation from the input, so the '.' at the end of sentence in the second test is incorrectly removed.
Couldn't work out how to leave the punctuation in :(
Brilliant!
The test suite should add commas and other punctuation.
10765 Solvers
23037 Solvers
Back to basics 20 - singleton dimensions
225 Solvers
Test if two numbers have the same digits
155 Solvers
Try 1.5.4: Celsius to Fahrenheit
486 Solvers