(line)
| 993 | } |
| 994 | |
| 995 | function codeToAction (line) { |
| 996 | const type = line.trim().split('(')[0].trim() |
| 997 | const directionStr = line.match(/'(up|down|left|right)'/)?.[1] |
| 998 | const direction = directionStr ? new Direction(directionStr) : undefined |
| 999 | const distanceStr = line.match(/(\d+)/)?.[1] |
| 1000 | const distance = distanceStr ? parseInt(distanceStr, 10) : undefined |
| 1001 | const forLoop = line.match(/for \(let (.+?) = 0; .+? < (\d+); \+?\+?.+?\+?\+?\) {/) |
| 1002 | const loopVariable = forLoop?.[1] |
| 1003 | const loopCountStr = forLoop?.[2] |
| 1004 | const loopCount = loopCountStr ? parseInt(loopCountStr, 10) : undefined |
| 1005 | return new Action({ type, direction, distance, loopVariable, loopCount }) |
| 1006 | } |
| 1007 | |
| 1008 | function actionToCode (action) { |
| 1009 | // This could be a method of Action class |
nothing calls this directly
no outgoing calls
no test coverage detected