wes d2a2ba9e15 first commit | пре 4 година | |
---|---|---|
.. | ||
README.md | пре 4 година | |
code.cpp | пре 4 година | |
unitTest.cpp | пре 4 година |
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).