wes d2a2ba9e15 first commit il y a 4 ans
..
README.md d2a2ba9e15 first commit il y a 4 ans
code.cpp d2a2ba9e15 first commit il y a 4 ans
unitTest.cpp d2a2ba9e15 first commit il y a 4 ans

README.md

Switcharoo

by Alex Golubov tags: strings, arrays, conditions, validation

Summary

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

Instructions

Create a function that takes a string and returns a new string with its first and last characters swapped, except under two conditions:

  1. If the length of the string is less than two, return "Incompatible.".
  2. If the first and last characters are the same, return "Two's a pair.".

Examples

flipEndChars("Cat, dog, and mouse.") ➞ ".at, dog, and mouseC"

flipEndChars("ada") ➞ "Two's a pair."

flipEndChars("Ada") ➞ "adA"

flipEndChars("z") ➞ "Incompatible."

Notes

Tests are case sensitive (e.g. "A" and "a" are not the same character).