Skip to content

Commit

Permalink
Add Duplicate Character Counter in Ruby (#3962)
Browse files Browse the repository at this point in the history
  • Loading branch information
msj4 authored Oct 31, 2024
1 parent 7b66500 commit f14e6e1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions archive/r/ruby/duplicate-character-counter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Duplicate Character Counter
if ARGV.length == 0 || ARGV[0] == ''
puts 'Usage: please provide a string'
else
hash_count_duplicate_letters = ARGV[0].each_char.with_object(Hash.new(0)) {|a, b| b[a]+=1}
counter_duplicate_letters = 0
hash_count_duplicate_letters.each do |key, value|
if value>1
puts "#{key}: #{value}"
counter_duplicate_letters += 1
end
end
if counter_duplicate_letters == 0
puts "No duplicate characters"
end
end
# end

0 comments on commit f14e6e1

Please sign in to comment.