Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
December 28, 2015 11:09
-
-
Save jdubnicek/7491894 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle class challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
class BoggleBoard | |
def initialize(dice_grid) | |
@dice_grid = dice_grid | |
end | |
def create_word(dice_grid, *coords) | |
coords.map { |coord| dice_grid[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
row = @dice_grid[row] | |
return row.join("") | |
end | |
def get_col(col) | |
column = [] | |
@dice_grid.each do |inner_array| | |
column << inner_array[col] | |
end | |
return column.join("") | |
end | |
end | |
board = BoggleBoard.new(dice_grid) | |
# implement tests for each of the methods here: | |
puts board.create_word(dice_grid, [1,2], [1,1], [2,1], [3,2]) | |
puts board.get_row(0) | |
puts board.get_row(1) | |
puts board.get_row(2) #=> returns "["e", "c", "l", "r"]" | |
puts board.get_row(3) | |
puts board.get_col(0) | |
puts board.get_col(1) | |
puts board.get_col(2) | |
puts board.get_col(3) #=> returns "["e", "t", "r", "e"]" | |
# create driver test code to retrieve a value at a coordinate here: | |
puts board.create_word(dice_grid, [3, 2]) #=> access coordinate "k" | |
#Since I am still catching up on the challenges I am skipping the BONUS for now. I will come back to | |
# it once I am caught up. | |
#REFLECTION: | |
#The biggest challenge for me was figuring out to remove the dice_grid hash outside the class. I had it inside | |
# and didnt need it there bc I am already passing it to the initialize method. Moving it outside the class then | |
# allowed for the creation of the new class instance "board". | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment