Unmix My Strings (Code Challenge)

  • Page Owner: Not Set
  • Last Reviewed: 2019-11-08

Unmix My Strings

lPaeesh le pemu mnxit ehess rtnisg! Oh, sorry, that was supposed to say: Please help me unmix these strings!

Somehow my strings have all become mixed up; every pair of characters has been swapped. Help me undo this so I can understand my strings again.

Examples

unmix("123456") ➞ "214365"

unmix("hTsii  s aimex dpus rtni.g") ➞ "This is a mixed up string."

unmix("badce") ➞ "abcde"

Notes

The length of a string can be odd — in this case the last character is not altered (as there's nothing to swap it with).

Tests

Test = (x, y) => x == y ? console.log("Pass", x, y) || true : console.log("Fail", x, y) || false;

unmix = x => x;

Test(unmix('123456'), '214365')
Test(unmix('hTsii  s aimex dpus rtni.g'),'This is a mixed up string.')
Test(unmix('badce'),'abcde')
Test(unmix(' Imaf eeilgna l tilt eidzz!y'),'I am feeling a little dizzy!')
Test(unmix(''), '', 'Should work with empty strings as well.')