// Separate Numbers with Commas in JavaScript **Pairing Challenge**


// I worked on this challenge with: Pete Wood.
// We worked on this assignment for 2.5 hours

// Pseudocode
// 1) Create a function called separateComma with an input of an integer
// 2) Convert the integer to a string "number"
// 3) ITERATE through the string
//      pass the values in reverse order to a new string called "reversed"
// 4) ITERATE through "reversed"
//      push each value to new string "reversedComma"
//      IF current iteration does not equal the length of the string,
//        every fourth iteration, insert a comma (",")
// 5) Reverse "reversedComma" to a new string called "finalNumber"
// 6) Return finalNumber


// Initial Solution

/*
var startNumber = 1234567890;

function separateComma(integerInput) {
  return integerInput.toString();
}

function reverseArray(stringIn){
    return stringIn.split("").reverse();
}

var reversed = reverseArray(separateComma(startNumber));
var reversedComma = reversed;
// console.log( startNumber.toString() );

for ( var i = 3; i < reversed.length; i += 4 ) {
    reversedComma.splice(i, 0, ",");
}
// console.log( reversedComma );

var finalNumber = reversedComma.reverse().join("");
console.log( "This is the final number: " + finalNumber );
*/

// RANDOM NOTES:
// join("");
// toString returns a string separated by commas!
// arr.splice(index, 0, item);
// reversedComma concat reversed[i]
// if i % 4 == 0

// Refactored Solution

function separateComma( integerIn )
{
  var reversedComma = integerIn.toString().split("").reverse();
  for ( var i = 3; i < reversedComma.length; i += 4 )
  {
    reversedComma.splice(i, 0, ",");
  }
  return reversedComma.reverse().join("");
}

console.log( separateComma( 1234567890 ) );
console.log( separateComma( 123456789 ) );
console.log( separateComma( 12345678 ) );
console.log( separateComma( 4192482489027 ) );


// Your Own Tests (OPTIONAL)




// Reflection

QUESTION: What was it like to approach the problem from the perspective of JavaScript? Did you approach the problem differently?
  ANSWER: It was interesting to pseudocode with the goal of coding in another language in mind because I noticed which words and concepts still apply sort of universally to both Ruby and Javascript but are still specific enough to be helpful. I approached the problem in the same general way though, creating functions instead of methods, making local variables, and iterating over data structures.

QUESTION: What did you learn about iterating over arrays in JavaScript?
  ANSWER:

QUESTION: What was different about solving this problem in JavaScript?
  ANSWER:

QUESTION: What built-in methods did you find to incorporate in your refactored solution?
  ANSWER:

@@ -1942,16 +1942,19 @@
 ection%0A%0A
+// 
 QUESTION
@@ -2016,16 +2016,19 @@
 spective
+%0A//
  of Java
@@ -2077,18 +2077,21 @@
 rently?%0A
+//
   
+ 
 ANSWER: 
@@ -2149,16 +2149,21 @@
 oding in
+%0A//  
  another
@@ -2222,16 +2222,21 @@
 concepts
+%0A//  
  still a
@@ -2295,16 +2295,21 @@
  but are
+%0A//  
  still s
@@ -2369,16 +2369,21 @@
 m in the
+%0A//  
  same ge
@@ -2445,16 +2445,21 @@
 , making
+%0A//  
  local v
@@ -2505,16 +2505,19 @@
 tures.%0A%0A
+// 
 QUESTION
@@ -2576,35 +2576,287 @@
 JavaScript?%0A
+//
   
+ 
 ANSWER:
-%0A%0A
+ I found that the for loop is very efficient and easy to%0A//   setup and use compared to incrementing while or until loops in%0A//   Ruby. Also many of the methods seem to be the same or very similar%0A//   to Ruby such as .split, .reverse, and .join.%0A%0A// 
 QUESTION: Wh
@@ -2914,16 +2914,19 @@
 Script?%0A
+// 
   ANSWER
@@ -2926,18 +2926,430 @@
  ANSWER:
-%0A%0A
+ The syntax for js was the part that seemed the most different%0A//   from Ruby, such as using the %7B%7D brackes for the loop like we would%0A//   for a block in Ruby, ending each statement with a semicolon ;, and%0A//     using console.log() with the function as an argument were some%0A//   slight differences. Buidling a function was ver similar to creating%0A//   methods in Ruby, so the overal structure was familiar.%0A%0A// 
 QUESTION
@@ -3407,16 +3407,19 @@
  in your
+%0A//
  refacto
@@ -3432,16 +3432,19 @@
 lution?%0A
+// 
   ANSWER
@@ -3444,9 +3444,283 @@
  ANSWER:
+ We used. split to separate a string into an array, .reverse%0A//   to reverse the order of the array, and .join to put the array back%0A//   together into a single string. We also used the .splice to insert%0A//   the commawhere it was needed. this was similar to inject in Ruby.
 %0A

Add reflections to nums_commas solution file