<commit_before># Calculate the mode Pairing Challenge

# I worked on this challenge [by myself, with: ]

# I spent [] hours on this challenge.

# Complete each step below according to the challenge directions and
# include it in this file. Also make sure everything that isn't code
# is commented.



# 0. Pseudocode

# What is the input?
# What is the output? (i.e. What should the code return?)
# What are the steps needed to solve the problem?


# 1. Initial Solution




# 3. Refactored Solution




# 4. Reflection<commit_msg>Add 5.3<commit_after># Calculate the mode Pairing Challenge

# I worked on this challenge with: <NAME>

# I spent [2] hours on this challenge.

# Complete each step below according to the challenge directions and
# include it in this file. Also make sure everything that isn't code
# is commented.



# 0. Pseudocode

# What is the input?
# an array of numbers or strings

# What is the output? (i.e. What should the code return?)
#  an assorted array of the most frequent values in the argument array

# What are the steps needed to solve the problem?
# identify unique elements
# count number of occurences of each unique element
# print element(s) with greatest number of occurences


# 1. Initial Solution

# def mode(array)

#   unique_array = array.uniq

#   count_array=[]
#   i = 0
#   while i < unique_array.length
#     count_array[i] = array.count(unique_array[i])
#     i += 1
#   end

#   count_hash = Hash[unique_array.zip count_array]

#   output_hash = Hash[count_hash.select { |key,value| value == count_array.max}]

#   p output_hash.keys

# end


# 3. Refactored Solution

# def mode(array)

#   count_hash = Hash.new(0)
#   array.each do |i|
#     count_hash[i]+=1
#   end

#   max_occurence = count_hash.values.max

#   output_hash = Hash[count_hash.select { |key,value| value == max_occurence}]
#   p output_hash.keys

# end


def mode(array)

  count_hash = array.inject(Hash.new(0)) { |hash,value| hash[value] += 1; hash }

  max_occurence = count_hash.values.max

  output_hash = Hash[count_hash.select { |key,value| value == max_occurence}]
  output_hash.keys

end


# 4. Reflection

# • Which data structure did you and your pair decide to implement and why?
# We decided to use hashes during this challenge because we needed to create a collection of objects that would allow key-based value retrieval.

# • Were you more successful breaking this problem down into implementable pseudocode than the last with a pair?
# I was more successful breaking this problem down into implementable pseudocode than the last with a pair. While pseudocode proved to be especially important in this challenge due to the difficulty of the material, it’s hard to write detailed pseudocode when you’re not sure what the built-in methods will allow you to do.

# • What issues/successes did you run into when translating your pseudocode to code?
# The biggest challenge was finding the right built-in methods. Learning the syntax for implementing the new methods was also a challenge, but the more familiar I become with Ruby syntax, the easier it is to learn new methods.

# • What methods did you use to iterate through the content? Did you find any good ones when you were refactoring? Were they difficult to implement?
# We initially used a while loop and basic methods to create code that would pass the tests. One useful method I learned when writing the initial solution was zip. zip allowed us to combine two arrays into a hash. When refactoring we researched and included several very useful methods. Figuring out how to implement inject proved to be quite challenging.

{'fraction_non_alphanumeric': 0.06631666206134292, 'fraction_numerical': 0.004697430229345123, 'mean_word_length': 3.925170068027211, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4107329', 'n_tokens_mistral': 1045, 'n_tokens_neox': 998, 'n_words': 497}