Skip to content

Instantly share code, notes, and snippets.

@srt32
Last active October 19, 2015 00:41
Show Gist options
  • Save srt32/56cd909626d9afc8713b to your computer and use it in GitHub Desktop.
Save srt32/56cd909626d9afc8713b to your computer and use it in GitHub Desktop.
require 'minitest'
require 'minitest/autorun'
class ReduceTest < Minitest::Test
def test_capitalize_keywords_in_phrase_one_fish_two_fish_red_fish_blue_fish
keywords = ["fish", "blue"]
phrase = 'one fish two fish red fish blue fish'
result = phrase.split.reduce do |updatedPhrase, word|
new_word = word
if keywords.include?(word)
new_word = word.upcase
end
updatedPhrase + " " + new_word # we want to keep a space between words
end
assert_equal 'one FISH two FISH red FISH BLUE FISH', result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment