{"size": 1258, "ext": "js", "max_stars_repo_path": "06.JavaScriptFundamentals/05.Arrays/scripts/05.Selection-sort.js", "max_stars_repo_name": "ykomitov/Homeworks-TA", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "06.JavaScriptFundamentals/05.Arrays/scripts/05.Selection-sort.js", "max_issues_repo_name": "ykomitov/Homeworks-TA", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "06.JavaScriptFundamentals/05.Arrays/scripts/05.Selection-sort.js", "max_forks_repo_name": "ykomitov/Homeworks-TA", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.6829268293, "max_line_length": 86, "alphanum_fraction": 0.5373608903}
var pr5 = function () {
    var arr_unsorted,
        arr_sorted = [],
        i,
        j,
        len,
        index,
        i_min_index;

    arr_unsorted = document.getElementById('problem5').value.split(',');

    //convert all elements of the array to numbers
    for (index in arr_unsorted) {
        arr_unsorted[index] = arr_unsorted[index] * 1;
    }

    console.log('Original array:');
    console.log(arr_unsorted);
    jsConsole.writeLine('<br>=================== Problem 5 ===================');
    jsConsole.writeLine('Array 1: ' + arr_unsorted);

    //perform selection sort algorithm - replace sorted element with Number.MAX_VALUE;
    for (i = 0, len = arr_unsorted.length; i < len; i += 1) {
        j = 0;
        i_min_index = 0;
        while (j < len) {
            if (arr_unsorted[i_min_index] > arr_unsorted[j]) {
                i_min_index = j;
            }
            j += 1;
        }
        //populate arr_sorted
        arr_sorted.push(arr_unsorted[i_min_index]);
        arr_unsorted[i_min_index] = Number.MAX_VALUE;
    }

    console.log('Sorted array:');
    console.log(arr_sorted);
    jsConsole.writeLine('Array 2: ' + arr_sorted);
    jsConsole.writeLine('=================================================');
}