In chat, we are often fast-typers and don't really look at the order of letters before posting a message. Since we are lazy, we need a program that automatically swaps the last two letters in our words, but since we don't want to respond too late, the code must be short.
Your task, if you wish to accept it, is to write a program that flips the last two letters of each word in a given string (so the word
Thansk turns into
Thanks). A word is a sequence of two or more letters in the English alphabet delimited by a single space.
The string / list of characters you receive as input is guaranteed to only contain alphabetic characters and spaces (ASCII [97 - 122], [65 - 90] and 32).
The output may have one trailing space and / or one trailing newline.
The input will always contain words only (and the corresponding whitespace) and will consist of at least one word.
This is code-golf, so the shortest submission (scored in bytes), in each language wins!
Note that the strings are surrounded with quotes for readability.
Input -> Output "Thansk" -> "Thanks" "Youer welcoem" -> "Youre welcome" "This is an apple" -> "Thsi si na appel" "Flippign Lettesr Aroudn" -> "Flipping Letters Around" "tHe oDd chALlEneg wiht swappde lettesR" -> "teH odD chALlEnge with swapped letteRs"
Or, for test suite convenience, here are the inputs and their corresponding outputs separately:
Thansk Youer welcoem This is an apple Flippign Lettesr Aroudn tHe oDd chALlEneg wiht swappde lettesR
Thanks Youre welcome Thsi si na appel Flipping Letters Around teH odD chALlEnge with swapped letteRs