<commit_before>
/* SEPARATE NUMBERS WITH COMMAS IN JAVASCRIPT : ** PAIRING CHALLENGE **

    WE WORKED ON THIS CHALLENGE: <NAME> and <NAME>

// ############################################### RELEASE 1: PSEUDOCODE

 INPUT: Any integer
OUTPUT: A string representing the integer separated with commas

Create a function that accepts the integer as a parameter
Convert integer into a string and split string into an array of individual characters
Reverse the array
Iterate over individual elements in the array
  Insert a comma every 3 characters
  Stop inserting commas when fewer than 3 characters remain
Reverse the array
Join elements of the array and convert back into a string
Output resulting string to console

*/
// ############################################### RELEASE 2: INITIAL SOLUTION

var number = function (num) {
  num = num.toString().split("").reverse();
  for (var index = 0; index < num.length - 3; index +=4){
      num.splice(index + 3, 0, ",");
  }
  num = num.reverse().join("")
  console.log(num)
}
num = 1000000
number(num)


// ############################################### RELEASE 4 : REFACTOR

var number = function(num) {
  answer = num.toString().split("").reverse();
  for (var index = 0; index < answer.length - 3; index +=4)
    answer.splice(index + 3, 0, ",");
    answer = answer.reverse().join("");
}

number(10000000)
console.log(answer)

// ############################################### RELEASE 3 : TESTS (OPTIONAL)

function assert(test, message, test_number) {
  if (!test) {
    console.log(test_number + "false");
    throw "ERROR: " + message;
  }
  console.log(test_number + "true");
  return true;
}

assert(
  (typeof answer === 'string'),
  "The value of answer should be a string.",
  "1. "
)

assert(
  answer === "10,000,000",
  "The value of answer should be 10,000,000.",
  "2. "
)


/*
// ############################################### RELEASE 5 : REFLECTION

1. What was it like to approach the problem from the perspective of JavaScript?
   Did you approach the problem differently?

    I think our pseudocode and logic are pretty similar to what we had for our Ruby
    solution, but the implementation in JavaScript was a little different and a bit
    more challenging because we are less familiar with it.

2. What did you learn about iterating over arrays in JavaScript?

    We learned that there aren't quite as many built-in methods for iterating over
    arrays in JavaScript as there are in Ruby. We also learned how to solve an issue
    that we were having with a locally scoped variable not being visible outside of
    our function.

3. What was different about solving this problem in JavaScript?

    Apart from the syntax, some of the methods were different in JavaScript. For
    example, JavaScript has #toString vs. #to_s in Ruby, Javascript has #splice
    vs. #insert in Ruby. We also had to find a way of giving our assert tests
    visibility to the variable that we used (answer). To do this we removed the
    keyword var from in front of the variable answer in our function.

4. What built-in methods did you find to incorporate in your refactored solution?

    We found the built-in methods #toString, #split, #reverse, #splice, and #join.


*/<commit_msg>Update refactoring on challenge 7.5<commit_after>
/* SEPARATE NUMBERS WITH COMMAS IN JAVASCRIPT : ** PAIRING CHALLENGE **

    WE WORKED ON THIS CHALLENGE: <NAME> and <NAME>

// ############################################### RELEASE 1: PSEUDOCODE

 INPUT: Any integer
OUTPUT: A string representing the integer separated with commas

Create a function that accepts the integer as a parameter
Convert integer into a string and split string into an array of individual characters
Reverse the array
Iterate over individual elements in the array
  Insert a comma every 3 characters
  Stop inserting commas when fewer than 3 characters remain
Reverse the array
Join elements of the array and convert back into a string
Output resulting string to console

*/
// ############################################### RELEASE 2: INITIAL SOLUTION

var number = function (num) {
  num = num.toString().split("").reverse();
  for (var index = 0; index < num.length - 3; index +=4){
      num.splice(index + 3, 0, ",");
  }
  num = num.reverse().join("")
  console.log(num)
}
num = 1000000
number(num)


// ############################################### RELEASE 4 : REFACTOR

var number = function(num) {
  num = num.toString().split("").reverse();

  for (var index = 0; index < num.length - 3; index +=4){
      num.splice(index + 3, 0, ",");
  }
  return num.reverse().join("");
};

// CALLING THE FUNCTION

var num = 10000000
number(10000000)
console.log(number(num))

// ############################################### RELEASE 3 : TESTS (OPTIONAL)

function assert(test, message, test_number) {
  if (!test) {
    console.log(test_number + "false");
    throw "ERROR: " + message;
  }
  console.log(test_number + "true");
  return true;
}

assert(
  (typeof number(num) === 'string'),
  "The value of num should be a string.",
  "1. "
)

assert(
  number(num) === "10,000,000",
  "The value of num should be 10,000,000.",
  "2. "
)

/*
// ############################################### RELEASE 5 : REFLECTION

1. What was it like to approach the problem from the perspective of JavaScript?
   Did you approach the problem differently?

    I think our pseudocode and logic are pretty similar to what we had for our Ruby
    solution, but the implementation in JavaScript was a little different and a bit
    more challenging because we are less familiar with it.

2. What did you learn about iterating over arrays in JavaScript?

    We learned that there aren't quite as many built-in methods for iterating over
    arrays in JavaScript as there are in Ruby.

3. What was different about solving this problem in JavaScript?

    Apart from the syntax, some of the methods were different in JavaScript. For
    example, JavaScript has #toString vs. #to_s in Ruby, Javascript has #splice
    vs. #insert in Ruby. We also had to find a way of giving our assert tests
    visibility to the variable that we used (num). To do this we *initially*
    created a globally scoped variable without the var keyword in our function.
    That worked, but we later realized that we could just return the value of
    num so long as it was declared outside of the function to begin with.

4. What built-in methods did you find to incorporate in your refactored solution?

    We found the built-in methods #toString, #split, #reverse, #splice, and #join.


*/
{'fraction_non_alphanumeric': 0.15177757520510482, 'fraction_numerical': 0.017927681555758128, 'mean_word_length': 3.8475699558173786, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '7422978', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1775, 'n_words': 837}