1var isRobotBounded = function (instructions) {2// north = 0, east = 1, south = 2, west = 33let directions = [4[0, 1],5[1, 0],6[0, -1],7[-1, 0],8];9// Initial position is in the center10let x = 0,11y = 0;12// facing north13let idx = 0;14let movements = [...instructions];1516for (let move of movements) {17if (move == "L") idx = (idx + 3) % 4;18else if (move == "R") idx = (idx + 1) % 4;19else {20x += directions[idx][0];21y += directions[idx][1];22}23}2425// after one cycle:26// robot returns into initial position27// or robot doesn't face north28return (x == 0 && y == 0) || idx != 0;29};