<commit_before># TODO: pluralize favourites in output string only if num != 1

class FavoriteQuestion < Badge
  series :favorite_question

  def progress_title
    "You're getting close to..."
  end

  def progress_description
    questions = service.fetch('users', 'questions', {
      ids: user_id,
      sort: 'votes',
      order: 'desc',
      filter: '!9cC8zbO*T',
      fetch_all_pages: true
    })
    
    # If only 1 question is returned, it is a Hash, not an array of Hashes 
    if (!questions.is_a? Array)
      questions = Array.new [questions]
    end
    
    if (questions.length > 0)
      highest_favorites_question = questions.first
      
      # Get badge with highest favorite_count
      if (questions.length > 1)
        highest_favorites_question = questions.reduce do |highest_favorites, question|
          question['favorite_count'] > highest_favorites['favorite_count'] ? question : highest_favorites
        end
      end
      
      title = highest_favorites_question['title']
      favorites = highest_favorites_question['favorite_count']
      remaining = required_favorites - favorites
    
      "Your question \"#{title.truncate(70)}\" has #{favorites} favorites. #{remaining} favorites to go!"<commit_msg>Remove trailing whitespace Steph shouldn't have committed<commit_after># TODO: pluralize favourites in output string only if num != 1

class FavoriteQuestion < Badge
  series :favorite_question

  def progress_title
    "You're getting close to..."
  end

  def progress_description
    questions = service.fetch('users', 'questions', {
      ids: user_id,
      sort: 'votes',
      order: 'desc',
      filter: '!9cC8zbO*T',
      fetch_all_pages: true
    })

    # If only 1 question is returned, it is a Hash, not an array of Hashes
    if (!questions.is_a? Array)
      questions = Array.new [questions]
    end

    if (questions.length > 0)
      highest_favorites_question = questions.first

      # Get badge with highest favorite_count
      if (questions.length > 1)
        highest_favorites_question = questions.reduce do |highest_favorites, question|
          question['favorite_count'] > highest_favorites['favorite_count'] ? question : highest_favorites
        end
      end

      title = highest_favorites_question['title']
      favorites = highest_favorites_question['favorite_count']
      remaining = required_favorites - favorites

      "Your question \"#{title.truncate(70)}\" has #{favorites} favorites. #{remaining} favorites to go!"
{'fraction_non_alphanumeric': 0.09214200239329877, 'fraction_numerical': 0.006382130035899481, 'mean_word_length': 3.125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1078422', 'n_tokens_mistral': 756, 'n_tokens_neox': 723, 'n_words': 207}