<commit_before>// Separate Numbers with Commas in JavaScript **Pairing Challenge**
// Submitted by <NAME>, 10/22/15

// I worked on this challenge with <NAME>.

/******************************* PSEUDOCODE **********************************\

Input: An integer
Output: That integer expressed as a string with commas in appropriate spots

Steps:
CONVERT integer to string
SPLIT string into array of single chars
REVERSE array
FOR loop
  SPLICE commas into array after every third char
JOIN array into a single string
REVERSE string
RETURN string


/****************************** INITIAL SOLUTION *****************************/

function separateComma(integer){
  var numbers = integer.toString().split("");
  var reverseNum = numbers.reverse();

  for(var counter = 3; counter < reverseNum.length ; counter += 4){
    reverseNum.splice(counter,0,",");
  };

  var output = reverseNum.reverse().join("");
  return output;
};


/**************************** REFACTORED SOLUTION ****************************/

// Refactored solution uses the same logic, but streamlines code by using one
// variable, number, throughout.

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

  for(var counter = 3; counter < number.length ; counter += 4) {
    number.splice(counter,0,",");
  };

  return number.reverse().join("");
};


/******************************** DRIVER CODE ********************************/

console.log(separateComma(1));
console.log(separateComma(12));
console.log(separateComma(123));
console.log(separateComma(1234));
console.log(separateComma(12345));
console.log(separateComma(123456));
console.log(separateComma(1234567));
console.log(separateComma(12345678));
console.log(separateComma(123456789));
console.log(separateComma(123456789123456789));


/******************************** REFLECTIONS ********************************\

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

I think the biggest difference was that we'd each solved the problem previously
in another language. We started by comparing what we remembered of our solution
algorithm from the previous challenge, chose a direction to pursue, and began
to write language-agnostic pseudocode. After that, we set about coding from the pseudocode, where our biggest challenge was figuring out how to accomplish tasks
in JavaScript that we already knew how to do in Ruby. We wound up doing a fair
amount of reference-checking in mid-session (it was too rushed to realistically
call it "research").
<commit_msg>Correct formatting error in 7.5 reflection<commit_after>// Separate Numbers with Commas in JavaScript **Pairing Challenge**
// Submitted by <NAME>, 10/22/15

// I worked on this challenge with <NAME>.

/******************************* PSEUDOCODE **********************************\

Input: An integer
Output: That integer expressed as a string with commas in appropriate spots

Steps:
CONVERT integer to string
SPLIT string into array of single chars
REVERSE array
FOR loop
  SPLICE commas into array after every third char
JOIN array into a single string
REVERSE string
RETURN string


/****************************** INITIAL SOLUTION *****************************/

function separateComma(integer){
  var numbers = integer.toString().split("");
  var reverseNum = numbers.reverse();

  for(var counter = 3; counter < reverseNum.length ; counter += 4){
    reverseNum.splice(counter,0,",");
  };

  var output = reverseNum.reverse().join("");
  return output;
};


/**************************** REFACTORED SOLUTION ****************************/

// Refactored solution uses the same logic, but streamlines code by using one
// variable, number, throughout.

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

  for(var counter = 3; counter < number.length ; counter += 4) {
    number.splice(counter,0,",");
  };

  return number.reverse().join("");
};


/******************************** DRIVER CODE ********************************/

console.log(separateComma(1));
console.log(separateComma(12));
console.log(separateComma(123));
console.log(separateComma(1234));
console.log(separateComma(12345));
console.log(separateComma(123456));
console.log(separateComma(1234567));
console.log(separateComma(12345678));
console.log(separateComma(123456789));
console.log(separateComma(123456789123456789));


/******************************** REFLECTIONS ********************************\

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

I think the biggest difference was that we'd each solved the problem previously
in another language. We started by comparing what we remembered of our solution
algorithm from the previous challenge, chose a direction to pursue, and began
to write language-agnostic pseudocode. After that, we set about coding from the
pseudocode, where our biggest challenge was figuring out how to accomplish tasks
in JavaScript that we already knew how to do in Ruby. We wound up doing a fair
amount of reference-checking in mid-session (it was too rushed to realistically
call it "research").

{'fraction_non_alphanumeric': 0.2028401458453272, 'fraction_numerical': 0.02916906543849549, 'mean_word_length': 5.656449553001277, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '7031745', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1314, 'n_words': 505}