src/controller.js
/**
   *Runs a set of commands on a particular rover
   *
   * @param {number} id the id of the rover on which to run the commands
   * @param {array} commands an array of well formed commands {command, value}
   * @returns {object} the updated location and direction of the rover {location, direction}
   * @memberof RoverController
   */
Runs a set of commands on a particular rover
@param {number} id the id of the rover on which to run the commands
@param {array} commands an array of well formed commands {command, value}
@returns {object} the updated location and direction of the rover {location, direction}
@memberof RoverController
Runs a set of commands on a particular rover @param { number } id the id of the rover on which to run the commands @param { array } commands an array of well formed commands { command value } @returns { object } the updated location and direction of the rover { location direction } @memberof RoverController
runCommands (id, commands) {
    if (id < 0 || id >= this.rovers.length) {
      throw new Error('invalid rover id')
    }
    let rover = this.rovers[id]
    commands.forEach((command) => {
      switch (command.command) {
        case 'rotate': {
          rover.rotate(command.value)
          break
        }
        case 'move': {
          rover.move()
          if (!this.isValidLocation(rover.location)) {
            rover.move({ reverse: true })
            throw new Error('cannot move off plateau')
          }
          break
        }
        default: {
          throw new Error('invalid rover command')
        }
      }
    })
    let location = rover.location
    let direction = rover.direction
    return { location, direction }
  }
runCommands ( id , commands ) { if ( id < 0 || id >= this . rovers . length ) { throw new Error ( 'invalid rover id' ) } let rover = this . rovers [ id ] commands . forEach ( ( command ) => { switch ( command . command ) { case 'rotate' : { rover . rotate ( command . value ) break } case 'move' : { rover . move ( ) if ( ! this . isValidLocation ( rover . location ) ) { rover . move ( { reverse : true } ) throw new Error ( 'cannot move off plateau' ) } break } default : { throw new Error ( 'invalid rover command' ) } } } ) let location = rover . location let direction = rover . direction return { location , direction } }
Runs a set of commands on a particular rover
 @param {number} id the id of the rover on which to run the commands
 @param {array} commands an array of well formed commands {command, value}
 @returns {object} the updated location and direction of the rover {location, direction}
 @memberof RoverController
Runs a set of commands on a particular rover @param { number } id the id of the rover on which to run the commands @param { array } commands an array of well formed commands { command value } @returns { object } the updated location and direction of the rover { location direction } @memberof RoverController