javascript - Switch numbers in string -


i have string space-separated unique numbers following:

"2 4 13 14 28 33" 

need quick , efficient way switch pair of them in form:

switchnumbers(2, 28) // result: "28 4 13 14 2 33" 

i split string , search values, sounds boring. better idea?

try also:

var numbers = "2 4 13 14 28 33";    function switchnum(from, to){    return numbers.replace(/\d+/g, function(num){      return num == ? : num == ? :  num    })  }    alert(switchnum(2, 28)) //result: "28 4 13 14 2 33"

note: not use switch function name, switch statement javascript.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -