牛牛去犇犇老师家补课,出门的时候面向北方,但是现在他迷路了。虽然他手里有一张地图,但是他需要知道自己面向哪个方向,请你帮帮他
var count=0;/*用来计数:向左加1,向右减1*/
function isDirection(num,str)
{
for (var i=0;i<str.length;i++)
{
if (str[i]==='L')
{
count=(count+1)%4;
}
else
{
if (str[i]==='R')
{
count=(count+3)%4;
}
}
}
var isDir;/*定义转向后的正确方向*/
switch (count)
{
case 0:isDir='N';break;
case 1:isDir='W';break;
case 2:isDir='S';break;
case 3:isDir='E';break;
}
return isDir;
}
print(isDirection(num,str));