Advertisement
brewersfan1976

check_equal_frequency.rb

Jan 29th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.40 KB | None | 0 0
  1. def checkEqualFrequency(inputArray)
  2.     counts = Hash.new 0
  3.    
  4.     inputArray.each do |number|
  5.         counts[number] += 1
  6.     end
  7.    
  8.     counts = counts.to_a
  9.  
  10.  
  11.     x = 0
  12.     value = counts[0][1]
  13.    
  14.     while (x < counts.length)
  15.           if counts[x][1] != value then
  16.              return false
  17.           end
  18.              
  19.           x = x + 1
  20.     end
  21.        
  22.     return true
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement