|
|
před 5 roky | |
|---|---|---|
| .. | ||
| README.md | před 5 roky | |
| code.cpp | před 5 roky | |
| unitTest.cpp | před 5 roky | |
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).