<commit_before>//Separate Numbers with Commas in JavaScript **Pairing Challenge**


// I worked on this challenge with: .

// Pseudocode
// Write a function  that takes a variable with an integer as an argument
// Convert integer to string, reverse and then split each number
// Make a counter that place a comma on every three indexes.
// Reverse and join into one string.
// Print it

// Initial Solution


var separateComma = function(num){
  var num_string = num.toString();
  var num_split = num_string.split("");
  var num_reverse = num_split.reverse();
  for (var i = 3; i < num_reverse.length; i += 3){
    num_reverse[i] += ",";
  };
  num_reverse.reverse();
  var result = num_reverse.join("");
  console.log(result);
};

separateComma(12345678);


// Refactored Solution

function separateComma(num){
  var num_string = num.toString().split("").reverse();
  for (var i = 3; i < num_string.length; i += 3){
    num_string[i] += ",";
  };
  var result = num_string.reverse().join("");
  console.log(result);
};

separateComma(12345678);

// Reflection

//What was it like to approach the problem from the perspective of JavaScript? Did you approach the problem differently?
// -
//What did you learn about iterating over arrays in JavaScript?
// -
//What was different about solving this problem in JavaScript?
// -
//What built-in methods did you find to incorporate in your refactored solution?
// -<commit_msg>add final touch<commit_after>//Separate Numbers with Commas in JavaScript **Pairing Challenge**


// I worked on this challenge with: .

// Pseudocode
// Write a function  that takes a variable with an integer as an argument
// Convert integer to string, reverse and then split each number
// Make a counter that place a comma on every three indexes.
// Reverse and join into one string.
// Print it

// Initial Solution


var separateComma = function(num){
  var num_string = num.toString();
  var num_split = num_string.split("");
  var num_reverse = num_split.reverse();
  for (var i = 3; i < num_reverse.length; i += 3){
    num_reverse[i] += ",";
  };
  num_reverse.reverse();
  var result = num_reverse.join("");
  console.log(result);
};

separateComma(12345678);


// Refactored Solution

function separateComma(num){
  var num_string = num.toString().split("").reverse();
  for (var i = 3; i < num_string.length; i += 3){
    num_string[i] += ",";
  };
  var result = num_string.reverse().join("");
  console.log(result);
};

separateComma(12345678);

// Reflection

//What was it like to approach the problem from the perspective of JavaScript? Did you approach the problem differently?
// - We used the same logic and we found methods in JS that worked in pretty much the same way. We had to work a little bit with the syntax to mae it work.
//What did you learn about iterating over arrays in JavaScript?
// - You don't iterate over arrays the way you do in Ruby, you use loops. We used a for loop.
//What was different about solving this problem in JavaScript?
// - Mainly the way to do an  iteration and the syntax
//What built-in methods did you find to incorporate in your refactored solution?
// - toString(), split(), reverse() and join()
{'fraction_non_alphanumeric': 0.1157960981749528, 'fraction_numerical': 0.012586532410320957, 'mean_word_length': 3.640875912408759, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '5135407', 'n_tokens_mistral': 953, 'n_tokens_neox': 906, 'n_words': 385}