Created
June 16, 2015 01:04
-
-
Save rossta/e56f90913c1a1398ab99 to your computer and use it in GitHub Desktop.
Num repeats challenge
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
irb(main):089:0> def num_repeats(string) | |
irb(main):090:1> counts = {} | |
irb(main):091:1> string.each_char{|k|counts[k] ||=0; counts[k] +=1} | |
irb(main):092:1> counts.select{|k,v| v > 1 }.length | |
irb(main):093:1> end | |
=> :num_repeats | |
irb(main):094:0> num_repeats | |
ArgumentError: wrong number of arguments (0 for 1) | |
from (irb):89:in `num_repeats' | |
from (irb):94 | |
from /Users/ross/.rubies/ruby-2.1.6/bin/irb:11:in `<main>' | |
irb(main):095:0> num_repeats("google") | |
=> 2 | |
irb(main):096:0> class Foo | |
irb(main):097:1> def num_repeats(string) | |
irb(main):098:2> string.length | |
irb(main):099:2> end | |
irb(main):100:1> end | |
=> :num_repeats | |
irb(main):101:0> num_repeats("google") | |
=> 2 | |
irb(main):102:0> Foo | |
=> Foo | |
irb(main):103:0> foo = Foo.new | |
=> #<Foo:0x007fe8aba560e0> | |
irb(main):104:0> foo.num_repeats | |
ArgumentError: wrong number of arguments (0 for 1) | |
from (irb):97:in `num_repeats' | |
from (irb):104 | |
from /Users/ross/.rubies/ruby-2.1.6/bin/irb:11:in `<main>' | |
irb(main):105:0> foo.num_repeats "google" | |
=> 6 | |
irb(main):106:0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment