src/rover.js
/**
   *Moves a rover one unit in its current direction
   *
   * @param {object} config with optional reverse parameter
   * @memberof Rover
   */
Moves a rover one unit in its current direction
@param {object} config with optional reverse parameter
@memberof Rover
Moves a rover one unit in its current direction @param { object } config with optional reverse parameter @memberof Rover
move (config) {
    const { reverse } = config || {}
    let nextLocation = this.location
    if (this.direction % 2 === 0) {
      let offset = (this.direction - 1) * (reverse ? -1 : 1)
      nextLocation = [this.location[0], this.location[1] - offset]
    } else {
      let offset = (this.direction - 2) * (reverse ? -1 : 1)
      nextLocation = [this.location[0] - offset, this.location[1]]
    }
    if (nextLocation.some(n => n < 0)) {
      throw new Error('cannot move into negative coordinates')
    }
    this.location = nextLocation
  }
move ( config ) { const { reverse } = config || { } let nextLocation = this . location if ( this . direction % 2 === 0 ) { let offset = ( this . direction - 1 ) * ( reverse ? - 1 : 1 ) nextLocation = [ this . location [ 0 ] , this . location [ 1 ] - offset ] } else { let offset = ( this . direction - 2 ) * ( reverse ? - 1 : 1 ) nextLocation = [ this . location [ 0 ] - offset , this . location [ 1 ] ] } if ( nextLocation . some ( n => n < 0 ) ) { throw new Error ( 'cannot move into negative coordinates' ) } this . location = nextLocation }
Moves a rover one unit in its current direction
 @param {object} config with optional reverse parameter
 @memberof Rover
Moves a rover one unit in its current direction @param { object } config with optional reverse parameter @memberof Rover
// moving left means [x, y] -> [x-1, y] // moving right means [x, y] -> [x+1, y] // moving up means [x, y] -> [x, y+1] // moving down means [x, y] -> [x, y-1] // if we are facing north or south // translate 0, 2 into -1, 1 // if we are facing west or east // translate 1 or 3 into -1, 1