6
const DIRECTIONS = [EAST, NORTH, WEST, SOUTH];10
* @param {number} width11
* @param {number} height13
var Robot = function (width, height) {17
this.path = []; // circular buffer of entire path of robot18
this.dirAtSquare = []; // dir robot is facing at each square25
* Loop around the map once and store the path into a circular buffer.27
* (0,0) is set to face SOUTH. The only time it is EAST is at the beginning28
* if the robot didn't move at all.32
Robot.prototype.preprocess = function () {34
for (let i = 1; i < this.width; i++) {35
this.path.push([i, 0]);36
this.dirAtSquare.push(0);40
const xMax = this.width - 1;41
for (let i = 1; i < this.height; i++) {42
this.path.push([xMax, i]);43
this.dirAtSquare.push(1);47
const yMax = this.height - 1;48
for (let i = xMax - 1; i >= 0; i--) {49
this.path.push([i, yMax]);50
this.dirAtSquare.push(2);55
for (let i = yMax - 1; i >= 0; i--) {56
this.path.push([xMin, i]);57
this.dirAtSquare.push(3);65
Robot.prototype.step = function (num) {66
this.currentPos += num;72
Robot.prototype.getPos = function () {73
return this.currentPos === -174
? ORIGIN // we haven't moved75
: this.path[this.currentPos % this.path.length];81
Robot.prototype.getDir = function () {82
return this.currentPos === -183
? DIRECTIONS[0] // we haven't moved84
: DIRECTIONS[this.dirAtSquare[this.currentPos % this.dirAtSquare.length]];88
* Your Robot object will be instantiated and called as such:89
* var obj = new Robot(width, height)91
* var param_2 = obj.getPos()92
* var param_3 = obj.getDir()