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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -