<commit_before>#include <stdio.h>

#define ARRAY_SIZE 5

int range(int array[], int length){
  int min = 0;
  int max = 0;

  int i;
  for (i=0; i < length; i++){
    // if the minimum number is larger than the value at index i
    // then we need to make the minimum number equal to this
    // value since it is our new minimum.
    if (min > array[i]){
      min = array[i];
    }

    // if the max number is less than the value at index i
    // then we need to make the max number equal to this
    // value, since it will be our new maximum.
    if (max < array[i]){
      max = array[i];
    }
  }

  // return the difference between the maximum and minimum
  // as this is our range.
  return max - min;
}

int sorted_range(int array[], int length){
  if (array[0] > array[length - 1]){
    return array[0] - array[length - 1];
  }

  if (array[0] < array[length - 1]){
    return array[length - 1] - array[0];
  }
}

int main(){
  // initialize our arrays to a range of -1 to 6 (range of 7)

  // this array is sorted from -1 to 6
  int my_min_max_sorted_array[ARRAY_SIZE] = {-1, 2, 3, 4, 6};
  // this array is sorted from 6 to -1
  int my_max_min_sorted_array[ARRAY_SIZE] = {6, 4, 3, 2, -1};
  // this array is not sorted
  int my_unsorted_array[ARRAY_SIZE] = {-1, 3, 2, 6, 4};

  int my_range;<commit_msg>add comments for sorted range function<commit_after>#include <stdio.h>

#define ARRAY_SIZE 5

int range(int array[], int length){
  int min = 0;
  int max = 0;

  int i;
  for (i=0; i < length; i++){
    // if the minimum number is larger than the value at index i
    // then we need to make the minimum number equal to this
    // value since it is our new minimum.
    if (min > array[i]){
      min = array[i];
    }

    // if the max number is less than the value at index i
    // then we need to make the max number equal to this
    // value, since it will be our new maximum.
    if (max < array[i]){
      max = array[i];
    }
  }

  // return the difference between the maximum and minimum
  // as this is our range.
  return max - min;
}

int sorted_range(int array[], int length){
  /*since this is a sorted array, we can assume that:

  we are going to have the max number as the first element
  and the min number as the last element
  OR
  we are going to have the min number as the first element
  and the max number as the last element.

  Therefore we must find which index has the minimum, and which
  has the maximum. We can then use max-min to determine the
  range as normal.
  */

  // the array has the maximum number as the first element
  // catches for arrays with: [max, ..., min]
  if (array[0] > array[length - 1]){
    // subtract the last element from the first element. (max-min)
    return array[0] - array[length - 1];
  }

  // the array has the minimum number as the first element
  // catches for arrays with: [min, ..., max]
  if (array[0] < array[length - 1]){
    // subtract the first element from the last element. (max-min)
    return array[length - 1] - array[0];
  }
}

int main(){
  // initialize our arrays to a range of -1 to 6 (range of 7)

  // this array is sorted from -1 to 6
  int my_min_max_sorted_array[ARRAY_SIZE] = {-1, 2, 3, 4, 6};
  // this array is sorted from 6 to -1
  int my_max_min_sorted_array[ARRAY_SIZE] = {6, 4, 3, 2, -1};
  // this array is not sorted
  int my_unsorted_array[ARRAY_SIZE] = {-1, 3, 2, 6, 4};

  int my_range;
{'fraction_non_alphanumeric': 0.11036299765807962, 'fraction_numerical': 0.01990632318501171, 'mean_word_length': 2.5446058091286305, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4322707', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1116, 'n_words': 510}