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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -