← Back to challenges

Swap X and Y Coordinates

JavaScriptHardstringsregex

Instructions

Write a function that swaps the X and Y coordinates in a string.

Examples

swapXY("(1, 2), (3, 4)") ➞ "(2, 1), (4, 3)"

swapXY("(11, 23), (43, 99)") ➞ "(23, 11), (99, 43)"

swapXY("(-5, -3), (7, 4)") ➞ "(-3, -5), (4, 7)"

Notes

  • Some numbers have multiple digits.
  • Some numbers will be negative.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.