657 机器人能否返回原点
1var judgeCircle = function(moves) {
2 let x = 0, y = 0;
3 for (let i = 0, l = moves.length; i < l; i++) {
4 if(moves[i] === 'U') {
5 y += 1;
6 } else if (moves[i] === 'D') {
7 y -= 1;
8 } else if (moves[i] === 'R') {
9 x += 1;
10 } else if (moves[i] === 'L') {
11 x -= 1;
12 }
13 }
14
15 return x === 0 && y === 0;
16};
17
18ensureEqual(judgeCircle('UD'), true, 'test 1');
19ensureEqual(judgeCircle('LL'), true, 'test 2');
20ensureEqual(judgeCircle('LR'), true, 'test 3');