1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
   | function solution (numbers, hand) {     let answer = '';     let keypad = {          1: [1,1], 2: [1,2], 3: [1,3],          4: [2,1], 5: [2,2], 6: [2,3],          7: [3,1], 8: [3,2], 9: [3,3],          '*': [4,1], 0: [4,2], '#': [4,3],      }     let curLeft = keypad['*']     let curRight = keypad['#']     numbers.forEach(num => {         let numPosition = keypad[num];
          if (numPosition[1] === 1) {             curLeft = numPosition             answer += 'L'         } else if (numPosition[1] === 3) {             curRight = numPosition             answer += 'R'         } else {             let distanceLeft = calDistance(curLeft, numPosition)             let distanceRight = calDistance(curRight, numPosition)
              if(distanceLeft === distanceRight) {                 if(hand === 'left') {                     curLeft = numPosition;                     answer += 'L'                 } else {                     curRight = numPosition;                     answer += 'R'                 }             } else if (distanceLeft < distanceRight) {                 curLeft = numPosition;                 answer += 'L';             } else {                 curRight = numPosition;                 answer += 'R';             }         }     })
      return answer; }
  function calDistance(LeftOrRight, numPosition) {     return Math.abs(LeftOrRight[0] - numPosition[0]) + Math.abs(LeftOrRight[1] - numPosition[1]) }
  |