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


// I worked on this challenge with: .

// Pseudocode



// Initial Solution




// Refactored Solution




// Your Own Tests (OPTIONAL)




// Reflection<commit_msg>Challenge 7.5 complete<commit_after>// Separate Numbers with Commas in JavaScript **Pairing Challenge**


// I worked on this challenge with: .

// Pseudocode



// Initial Solution
// function commas(number) {
//     var num_string = new String(number);
//     var len = num_string.length;
//     var array = num_string.split("");
    
//     if (len < 4) {
//         return array.join("");
//     }
//     else {
//         var comma_start = -3; 
//         var insert_count = 0;
        
//         while (comma_start > -len) {
//             var insert_pos = comma_start + insert_count;
//             array.splice(insert_pos, 0, ",");
//             insert_count--;
//             comma_start -= 3;
//         } 
        
//         return array.join("");
//     }
// }



// Refactored Solution
function commas_refactor(number) {
    var array = new String(number).split("");
    var len = array.length;
    
    if (len < 4) {
        return array.join("");
    }
    else {
        var insert_pos = -3;
        
        while (insert_pos > -len) {
            array.splice(insert_pos, 0, ",");
            insert_pos -= 4;
        } 
        
        return array.join("");
    }
}



// Your Own Tests (OPTIONAL)




// Reflection
// What was it like to approach the problem from the perspective of JavaScript? Did you approach the problem differently?
// No. It was still break it into small bits and tackle each small bit first. It was just about looking through the docs to see what methods JS has to offer, and how they work. 

// What did you learn about iterating over arrays in JavaScript?
// Same as with ruby, its just that the terminalogy is more similar to Java than to Python for Ruby

// What was different about solving this problem in JavaScript?
// JS is heavily influenced by Java syntax and getting to know the methods and syntax is different. 

// What built-in methods did you find to incorporate in your refactored solution?
// .splice, .split and .join methods
{'fraction_non_alphanumeric': 0.10838537020517396, 'fraction_numerical': 0.004906333630686887, 'mean_word_length': 2.081043956043956, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '198412', 'n_tokens_mistral': 656, 'n_tokens_neox': 616, 'n_words': 242}