src/util.js
/**
 *Parses a command string into an array of well-formed commands
 *
 * @param {string} str the input string in the form 'LMLMLMLMM'
 * @returns {array} an array of command objects consumable by a rover controller
 */
Parses a command string into an array of well-formed commands
@param {string} str the input string in the form 'LMLMLMLMM'
@returns {array} an array of command objects consumable by a rover controller
Parses a command string into an array of well - formed commands @param { string } str the input string in the form ' LMLMLMLMM ' @returns { array } an array of command objects consumable by a rover controller
function parseCommands (str) {
  if (typeof str !== 'string') {
    throw new Error('command string must be a string')
  }
  return str.split('').map(x => {
    switch (x) {
      case 'L':
        return { command: 'rotate', value: -1 }
      case 'R':
        return { command: 'rotate', value: 1 }
      case 'M':
        return { command: 'move' }
      default:
        throw new Error('invalid command string')
    }
  })
}
function parseCommands ( str ) { if ( typeof str !== 'string' ) { throw new Error ( 'command string must be a string' ) } return str . split ( '' ) . map ( x => { switch ( x ) { case 'L' : return { command : 'rotate' , value : - 1 } case 'R' : return { command : 'rotate' , value : 1 } case 'M' : return { command : 'move' } default : throw new Error ( 'invalid command string' ) } } ) }
Parses a command string into an array of well-formed commands
 @param {string} str the input string in the form 'LMLMLMLMM'
 @returns {array} an array of command objects consumable by a rover controller
Parses a command string into an array of well - formed commands @param { string } str the input string in the form ' LMLMLMLMM ' @returns { array } an array of command objects consumable by a rover controller