wes d2a2ba9e15 first commit | vor 4 Jahren | |
---|---|---|
.. | ||
README.md | vor 4 Jahren | |
code.cpp | vor 4 Jahren | |
unitTest.cpp | vor 4 Jahren |
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).