Last active
June 8, 2017 04:07
-
-
Save muhammadyana/9495c2b652b0499271c0fbe6ec264f0f to your computer and use it in GitHub Desktop.
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
# | |
# require_relative 'words_from_string' | |
# require 'test/unit' | |
# | |
# class TestWordsFromString < Test::unit::Testcase | |
# def test_empty_string | |
# assert_equal( | |
# [], words_from_string("") | |
# ) | |
# assert_equal( | |
# [], words_from_string(" ") | |
# ) | |
# end | |
# def test_single_word | |
# assert_equal( | |
# ["cat"], words_from_string("cat") | |
# ) | |
# assert_equal( | |
# ["cat"], words_from_string(" cat ") | |
# ) | |
# end | |
# def test_many_woords | |
# assert_equal( | |
# ["the", "cat", "sat", "on", "the", "mat"], | |
# words_from_string("the cat sat on the mat") | |
# ) | |
# end | |
# def test_ignores_punctutation | |
# assert_equal( | |
# ["the", "cat's", "mat"], | |
# words_from_string("<the!> cat's, -mat-") | |
# ) | |
# end | |
# end | |
# | |
def to_max(max) | |
i1, i2 = 1, 1 | |
while i1 <= max | |
yield i1 | |
i1, i2 = i2, i1+i2 | |
end | |
end | |
# to_max(21){ | |
# |f| print f, " " | |
# } | |
# puts | |
class Array | |
def find | |
each do |value| | |
return value if yield(value) | |
end | |
nil | |
end | |
end | |
# tes = Array.new | |
# puts tes.find |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment