Here I created hashmap array and created one function.
var rule =
{
"c": "d",
"a": "o",
"t": "g",
"h": "a",
"1":"@",
"e": "n",
"n": "t"
}
function convert(str) {
return [...str].map(d => rule[d]).join('')
}
console.log(convert("cat1hen"))
It display output as "dog@ant".But I want different output.Everytime there is expected output as "@",I want to swap "@" to swap its value with next array element.
It means output should be "doga@nt" instead of "dog@ant".Here position of @ is swapped with its next array element i.e "a". The position should be swapped only when expected output is "@".