Swapping Two by Two

Published by Helen Yu in

Write a function that swaps the first pair (1st and 2nd characters) with the second pair (3rd and 4th characters) for every quadruplet substring.

Examples

swap_two("ABCDEFGH") ➞ "CDABGHEF"

swap_two("AABBCCDDEEFF") ➞ "BBAADDCCFFEE"

swap_two("munchkins") ➞ "ncmuinhks"

swap_two("FFGGHHI") ➞ "GGFFHHI"

Notes

Keep leftover strings in the same order.

Watch a quick demo on how Edabit works.