Skip to content

Instantly share code, notes, and snippets.

@kangkyu
Created November 2, 2015 06:51
Show Gist options
  • Save kangkyu/44b57122b520c50f3d99 to your computer and use it in GitHub Desktop.
Save kangkyu/44b57122b520c50f3d99 to your computer and use it in GitHub Desktop.
# She has asked you to create a method print_puzzle that prints the row of dashes for a required, single argument, word. The number of dashes or spaces should equal the amount of characters in the word. print_puzzle can also optionally take a list of characters as a second argument that represents the list of guessed letters.
# Given print_puzzle is called with the word "perimeter", your method should output: _ _ _ _ _ _ _ _ _
# Given print_puzzle is called with the word "triangle" and the list of characters guessed: t,s,g, your method should output: t _ _ _ _ g _ _
def print_puzzle(word, guessed_letters = [])
word.chars.map {|char| guessed_letters.include?(char) ? " #{char}" : " _"}.join
end
gem 'minitest'
require 'minitest/autorun'
class TestHang < Minitest::Test
def test_perimeter
assert_equal " _ _ _ _ _ _ _ _ _", print_puzzle("perimeter")
end
def test_triangle
assert_equal " t _ _ _ _ g _ _", print_puzzle("triangle", ['t', 's', 'g'])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment