I have a string with space-separated unique numbers as following:
"2 4 13 14 28 33"
Need a quick and efficient way to switch a pair of them in form:
switchNumbers(2, 28)
// result: "28 4 13 14 2 33"
I could split the string and search for values, but that sounds boring. Any better idea?
Try also:
Note: Do not use
switch
as function name, switch is a statement for JavaScript.