// Create a function separateComma. It should accept an integer as an argument and return a comma-separated integer as a string.

// Pseudocode
// Input: Integer
// Output: String
// Steps: IF integer is 3 digits or less, return number
// ELSE IF integer is greater than 3 digits, transform integer into an array. LOOP through array and add a comma after every third digit

// commas_needed = number.length / 3 IF number.length % 3 != 0
// commas_needed 

function commas(number) {
  var commasNeeded = Math.floor(String(number).length/3);
  var digitArray = String(number).split("").reverse();
  if (String(number).length <= 3) {
    return number;
  } else {
    if (String(number).length == 4) {
      digitArray.splice(3, 0, ",");;
    } else {
      digitArray.splice(3, 0, ",");
      var commaPosition = 7;
      for (var i = 0; i < commasNeeded - 1; i++) {
        digitArray.splice(commaPosition, 0, ",");
        commaPosition += 4;
      }
    }
  }
  if (String(number).length % 3 === 0) {
    digitArray.reverse().shift();
    return digitArray.join("");
  } else {
    return digitArray.reverse().join("");
  }
};


// Refactored Solution




// Your Own Tests (OPTIONAL)

console.log(commas(100));
console.log(commas(1000));
console.log(commas(12345678956));
console.log(commas(123456789565));


// Reflection


// Refactored Solution




// Your Own Tests (OPTIONAL)




// Reflection
@@ -1,8 +1,76 @@
+// I worked on this challenge with Oscar DelGadillo for 2.5 hours.%0A%0A
 // Creat
@@ -517,16 +517,786 @@
 eeded %0A%0A
+// function commas(number) %7B%0A//   var commasNeeded = Math.floor(String(number).length/3);%0A//   var digitArray = String(number).split(%22%22).reverse();%0A//   if (String(number).length %3C= 3) %7B%0A//     return number;%0A//   %7D else %7B%0A//     if (String(number).length == 4) %7B%0A//       digitArray.splice(3, 0, %22,%22);;%0A//     %7D else %7B%0A//       digitArray.splice(3, 0, %22,%22);%0A//       var commaPosition = 7;%0A//       for (var i = 0; i %3C commasNeeded - 1; i++) %7B%0A//         digitArray.splice(commaPosition, 0, %22,%22);%0A//         commaPosition += 4;%0A//       %7D%0A//     %7D%0A//   %7D%0A//   if (String(number).length %25 3 === 0) %7B%0A//     digitArray.reverse().shift();%0A//     return digitArray.join(%22%22);%0A//   %7D else %7B%0A//     return digitArray.reverse().join(%22%22);%0A//   %7D%0A// %7D;%0A%0A%0A// Refactored Solution%0A%0A
 function
@@ -1426,16 +1426,17 @@
 erse();%0A
+%0A
   if (St
@@ -1482,24 +1482,28 @@
 number;%0A  %7D 
+%0A%0A  
 else %7B%0A    i
@@ -1574,24 +1574,30 @@
 ,%22);;%0A    %7D 
+%0A%0A    
 else %7B%0A     
@@ -1656,16 +1656,17 @@
 on = 7;%0A
+%0A
       fo
@@ -1977,65 +1977,8 @@
 ;%0A%0A%0A
-// Refactored Solution%0A%0A%0A%0A%0A// Your Own Tests (OPTIONAL)%0A%0A
 cons
@@ -2116,78 +2116,1034 @@
 on%0A%0A
-%0A
 // 
-Refactored Solution%0A%0A%0A%0A%0A// Your Own Tests (OPTIONAL)%0A%0A%0A%0A%0A// Reflection
+What was it like to approach the problem from the perspective of JavaScript? Did you approach the problem differently?%0A// It was tougher than I was anticipating because JavaScript doesn't have as many built-in methods but our logic was basically the same as the logic from our Ruby challenge but slightly different because working with a partner yielded slightly different logic. %0A%0A// What did you learn about iterating over arrays in JavaScript?%0A// Not too much in this challenge, as we used the built-in .splice method a few times which worked like a charm! We used a for loop only once and it was pretty straight forward.%0A%0A// What was different about solving this problem in JavaScript?%0A// At times, my pair and I got our syntaxes mixed up and had to do remember to use our brackets and semi-colons! %0A%0A// What built-in methods did you find to incorporate in your refactored solution?%0A// I didn't do much refactoring between my intitial solution and my refactored solution. We used .splice, .shift, .reverse, and Math.floor.%0A

complete assignment