src/util.js
/**
 *Parses a rover string into its initial location and direction
 *
 * @param {string} str the input string of the form '1 2 N'
 * @returns {object} the location and direction of the rover
 */
Parses a rover string into its initial location and direction
@param {string} str the input string of the form '1 2 N'
@returns {object} the location and direction of the rover
Parses a rover string into its initial location and direction @param { string } str the input string of the form ' 1 2 N ' @returns { object } the location and direction of the rover
function parseRover (str) {
  if (typeof str !== 'string') {
    throw new Error('rover input must be a string')
  }
  const [x, y, directionString] = str.split(' ')
  const location = [x, y].map(Number)
  const directions = { 'N': 0, 'E': 1, 'S': 2, 'W': 3 }
  const direction = directions[directionString]
  if (typeof direction === 'undefined') {
    throw new Error('invalid direction in rover string')
  }
  return { location, direction }
}
function parseRover ( str ) { if ( typeof str !== 'string' ) { throw new Error ( 'rover input must be a string' ) } const [ x , y , directionString ] = str . split ( ' ' ) const location = [ x , y ] . map ( Number ) const directions = { 'N' : 0 , 'E' : 1 , 'S' : 2 , 'W' : 3 } const direction = directions [ directionString ] if ( typeof direction === 'undefined' ) { throw new Error ( 'invalid direction in rover string' ) } return { location , direction } }
Parses a rover string into its initial location and direction
 @param {string} str the input string of the form '1 2 N'
 @returns {object} the location and direction of the rover
Parses a rover string into its initial location and direction @param { string } str the input string of the form ' 1 2 N ' @returns { object } the location and direction of the rover