<commit_before>// getMax - this function will take an array of integers and find
// the max value in that array.
//
// Example:
// getMax([1,2,3])
// > 3
function getMax(arr) {
    // if the array is empty, return undefined
    if(arr.length == 0) {
        return undefined;
    }
    var max = arr[0];
    for(var i = 0; i < arr.length; i++) {
        if(max < arr[i]) {
            max = arr[i];
        }
    }
    
    return max;
}

// getMin - this function will take an array of integers and find
// the min value in that array.
//
// Example:
// getMin([1,2,3])
// > 1
function getMin(arr) {
    // if the array is empty, return undefined
    if(arr.length == 0) {
        return undefined;
    }
    var min = arr[0];
    for(var i = 0; i < arr.length; i++) {
        if(min > arr[i]) {
            min = arr[i];
        }
    }

    return min;
}

// testing out getMax()
console.log("Tests for getMax():");
console.log(getMax([1,2,3]) + " == 3");
console.log(getMax([5,2,4]) + " == 5");
console.log(getMax([-1,-2,-3]) + " == -1");
console.log(getMax([10]) + " == 10");
console.log(getMax([]) + " == undefined");

// testing out getMin()
console.log("Tests for getMin():");
console.log(getMin([1,2,3]) + " == 1");
console.log(getMin([5,2,4]) + " == 2");
console.log(getMin([-1,-2,-3]) + " == -3");
console.log(getMin([10]) + " == 10");
console.log(getMin([]) + " == undefined");

<commit_msg>Adding two assert functions and then using them to verify the results of my functions.<commit_after>/*
 * sorts.js - a variety of sorting algorithms and other functions
 */


// assert - this function will wrap the above assert method and
// remove the need to pass in a string, instead, the expression
// that is given will be used as the message passed into assert.
function assert(expression) {
    assert(expression, '');
}

// assert - this function will add support for assertions. Two items
// can be passed in and their equality will be tested. If they are
// evaluated to be equal, then the function will silently return,
// otherwise an error will be thrown using the message given in the
// second argument.
//
// This function will add support for assertions so that I
// can actually do quick inline testing of my code to see that certain
// properties hold during execution and that the outputs of functions
// are what I expect.
//
// Example:
// assert(4<5, "comparing 4 and 5");
// > undefined
// assert(4>5, "comparing 4 and 5");
// > Error: Assertion Violated: comparing 4 and 5
function assert(expression, message) {
    if(!expression) {
        var errorMessage = '';
        if(message) {
            errorMessage = "Assertion Violated: " + message;
        }
        else {
            errorMessage = "Assertion Violated";
        }

        throw new Error(errorMessage);
    }
}


// getMax - this function will take an array of integers and find
// the max value in that array.
//
// Example:
// getMax([1,2,3])
// > 3
function getMax(arr) {
    // if the array is empty, return undefined
    if(arr.length == 0) {
        return undefined;
    }
    var max = arr[0];
    for(var i = 0; i < arr.length; i++) {
        if(max < arr[i]) {
            max = arr[i];
        }
    }
    
    return max;
}

// getMin - this function will take an array of integers and find
// the min value in that array.
//
// Example:
// getMin([1,2,3])
// > 1
function getMin(arr) {
    // if the array is empty, return undefined
    if(arr.length == 0) {
        return undefined;
    }
    var min = arr[0];
    for(var i = 0; i < arr.length; i++) {
        if(min > arr[i]) {
            min = arr[i];
        }
    }

    return min;
}

// testing out getMax()
assert(getMax([1,2,3]) == 3, "using getMax");
assert(getMax([5,2,4]) == 5, "using getMax");
assert(getMax([-1,-2,-3]) == -1, "using getMax");
assert(getMax([10]) == 10);
assert(getMax([]) == undefined);

// testing out getMin()
assert(getMin([1,2,3]) == 1);
assert(getMin([5,2,4]) == 2);
assert(getMin([-1,-2,-3]) == -3);
assert(getMin([10]) == 10);
assert(getMin([]) == undefined);


{'fraction_non_alphanumeric': 0.16838995568685378, 'fraction_numerical': 0.025110782865583457, 'mean_word_length': 2.5546806649168854, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '5536380', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1312, 'n_words': 438}