Open JoshCheek opened 5 years ago
Before running:
def alphabet_position(str) str.scan(/\[a-z]/i).map { |c| c.ord & 0b11111 }.join(' ') end def assert_equals(actual, expected) raise RuntimeError, "#{actual}\n#{expected}", caller unless actual == expected end assert_equals( alphabet_position("The sunset sets at twelve o' clock."), "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" ) assert_equals( alphabet_position("The narwhal bacons at midnight."), "20 8 5 14 1 18 23 8 1 12 2 1 3 15 14 19 1 20 13 9 4 14 9 7 8 20" )
After running:
def alphabet_position(str) str.scan(/\[a-z]/i).map { |c| c.ord & 0b11111 }.join(' ') end def assert_equals(actual, expected) raise RuntimeError, "#{actual}\n#{expected}", caller unless actual == expected end assert_equals( # ~> RuntimeError: \n20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11 alphabet_position("The sunset sets at twelve o' clock."), "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" ) assert_equals( alphabet_position("The narwhal bacons at midnight."), "20 8 5 14 1 18 23 8 1 12 2 1 3 15 14 19 1 20 13 9 4 14 9 7 8 20" ) # ~> RuntimeError # ~> # ~> 20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11 # ~> # ~> program.rb:9:in `<main>'/Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/ /Users/josh/.gem/ruby/2.5.1/gems/parser-2.5.1.2/lib/parser/builders/default.rb:1635: warning: regular expression has ']' without escape: /\[a-z]/
NOTE: The regex accidentally escaped the character set (b/c it used to be /\w/ and I forgot to take out the escape)
/\w/
Before running:
After running: