function solution(dirs) {
var answer = 0;
let cur={x:0,y:0};
let obj={
'U':(pos)=>pos.y<5?pos.y+=1:pos.y=5,
'D':(pos)=>pos.y>-5?pos.y-=1:pos.y=-5,
'R':(pos)=>pos.x<5?pos.x+=1:pos.x=5,
'L':(pos)=>pos.x>-5?pos.x-=1:pos.x=-5,
}
let pathSet=new Set();
[...dirs].forEach((dir)=>{
const pre={...cur};
obj[dir](cur);
const path=[`${pre.x}${pre.y}`,`${cur.x}${cur.y}`].sort();
console.log(path)
pathSet.add(path.join('=>'));
})
console.log(...pathSet)
return [...pathSet].map(e=>e.split('=>')).filter(e=>e[0]!==e[1]).length;
}