Skip to content

Commit

Permalink
Refactor turn left to remove case/when
Browse files Browse the repository at this point in the history
  • Loading branch information
ColumODonovann committed Nov 10, 2023
1 parent 64cf935 commit 737fc65
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/mars_rover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
class MarsRover
attr_reader :point

LEFT_LOOKUP = {
'E' => 'N',
'S' => 'E',
'W' => 'S',
'N' => 'W'
}

def initialize(point)
@point = point
end
Expand Down Expand Up @@ -55,18 +62,7 @@ def move_backward
end

def turn_left
case point.direction
when 'E'
new_direction = 'N'
when 'S'
new_direction = 'E'
when 'W'
new_direction = 'S'
when 'N'
new_direction = 'W'
end

@point = Point.new(@point.x, @point.y, new_direction)
@point = Point.new(@point.x, @point.y, LEFT_LOOKUP[point.direction])
end


Expand Down

0 comments on commit 737fc65

Please sign in to comment.