<commit_before># Numbers to Commas Solo Challenge

# I did this challenge by myself.
# I spent 3 hours on this challenge.

# 0. Pseudocode for Unrefactored Solution

# What is the input?
# => The input is a positive integer.
# What is the output? (i.e. What should the code return?)
# => The output is a comma-separated integer as a string.
# What are the steps needed to solve the problem?
# => Define a method which takes a single argument of positive integer.
# => Check if the argument is positive.
# => If the argument is not positive, return nil!
# => If it is positive, continue with method body
# => Create a new array to store the chunks.
# => Take the number_to_separate and convert it to a string and reverse the number.
# => Scan the number into chunks of 3 characters or 'one or more digits'(remaining digits) until end of the line.
# => Put the chunks into the array which we created before.
# => Then, combine the chunks with ',' between the chunks
# => Reversing the string back.

# 1. Initial Solution
def separate_comma(number_to_separate)
  return nil if number_to_separate < 0
  numbers=[]
  numbers.unshift(number_to_separate.to_s.reverse.scan(/...|\d+$/)).join(',').reverse
end
p  separate_comma(1234627900)

# 1. Pseudocode for refactored solution
# => Define a method which takes a single argument of positive integer.
# => Check if the argument is positive. If the argument is not positive, return nil!
# => If it is positive, continue with method body
# => Take the number_to_separate and convert it to a string. Then, reverse it.
# => Scan the number into chunks of 3 characters or 'one or more digits'(remaining digits) until end of the line.<commit_msg>Include non-regex comma<commit_after># Numbers to Commas Solo Challenge

# I did this challenge by myself.
# I spent 3 hours on this challenge.

# 0. Pseudocode for Unrefactored Solution

# What is the input?
# => The input is a positive integer.
# What is the output? (i.e. What should the code return?)
# => The output is a comma-separated integer as a string.
# What are the steps needed to solve the problem?
# Convert the number to a string and reverse it permanently.
# Define a starting index of 0.
# Whenever the length of the string minus 3 is greater than the index,
# It insert a comma at the index of whatever the index + 3 is.
# It adds four to the index, and it reverses the number back, then outputs the numbers to the console.

# 0. Initial solution
def separate_comma(number_to_separate)
  return nil if number_to_separate < 0
  number_separate = number_to_separate.to_s.reverse!
  #Defining a starting index of 0.
  index = 0 ;
  #inspect(index, obj) => insert the given values before the element with the given index.
  # inserting comma every 3 digits.
  while index < number_separate.length - 3
    number_separate.insert(index + 3, ",")
    index += 4
  end
  number_separate.reverse!
  p number_separate
end
separate_comma(99912345)

# The following solutions are made by Regex.
# => Define a method which takes a single argument of positive integer.
# => Check if the argument is positive.
# => If the argument is not positive, return nil!
# => If it is positive, continue with method body
# => Create a new array to store the chunks.
# => Take the number_to_separate and convert it to a string and reverse the number.
# => Scan the number into chunks of 3 characters or 'one or more digits'(remaining digits) until end of the line.
# => Put the chunks into the array which we created before.
# => Then, combine the chunks with ',' between the chunks
# => Reversing the string back.

# 1. First Solution Before Refactored Solution
def separate_comma(number_to_separate)
  return nil if number_to_separate < 0
  numbers=[]
  numbers.unshift(number_to_separate.to_s.reverse.scan(/...|\d+$/)).join(',').reverse
end
p  separate_comma(1234627900)

# 1. Pseudocode for refactored solution
# => Define a method which takes a single argument of positive integer.
# => Check if the argument is positive. If the argument is not positive, return nil!
# => If it is positive, continue with method body
# => Take the number_to_separate and convert it to a string. Then, reverse it.
# => Scan the number into chunks of 3 characters or 'one or more digits'(remaining digits) until end of the line.
{'fraction_non_alphanumeric': 0.07905783582089553, 'fraction_numerical': 0.012360074626865671, 'mean_word_length': 4.039952996474736, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, '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': '5544047', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1189, 'n_words': 606}