wes d2a2ba9e15 first commit | 4 years ago | |
---|---|---|
.. | ||
README.md | 4 years ago | |
code.cpp | 4 years ago | |
unitTest.cpp | 4 years ago |
by Alex Golubov tags: strings, arrays, conditions, validation
Create a function that takes a string and returns a new string with its first and last characters swapped, except under two conditions: If the length of the string is less than two, return "Incompatible.". If the first and last characters are the same, return "Two's a pair.". Examples flipEndChars("Cat, dog, and mouse.") ➞ ".at, dog, and mouseC" flipEndChar
Create a function that takes a string and returns a new string with its first and last characters swapped, except under two conditions:
"Incompatible."
."Two's a pair."
.flipEndChars("Cat, dog, and mouse.") ➞ ".at, dog, and mouseC"
flipEndChars("ada") ➞ "Two's a pair."
flipEndChars("Ada") ➞ "adA"
flipEndChars("z") ➞ "Incompatible."
Tests are case sensitive (e.g. "A" and "a" are not the same character).