Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:55
-
-
Save sjafri5/8744836 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
This file contains hidden or 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
class Boggle | |
def initialize(board) | |
@board = board | |
end | |
def get_letter(row, col) | |
@board[row][col] | |
end | |
def create_word(*coords) | |
coords.map { |coord| @board[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
@board[row].inspect | |
end | |
def get_column(column) | |
column_array = Array.new | |
@board.each { |e| column_array.push(e[column]) } | |
column_array.inspect # Remove #inspect to see as a column. | |
end | |
end | |
# implement tests for each of the methods here: | |
dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
boggle_board = Boggle.new(dice_grid) | |
# implement tests for each of the methods here: | |
puts "==========" | |
puts boggle_board.get_letter(0, 0) == "b" | |
puts boggle_board.create_word([0, 0], [0, 1], [1, 1]) == "bro" | |
puts boggle_board.get_row(0) == ["b", "r", "a", "e"] | |
puts boggle_board.get_column(0) == ["b", "i", "e", "t"] | |
# create driver test code to retrieve a value at a coordinate here: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment