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
Post a Comment