<commit_before><!--
Bubble Sort mini-proficiency exercise.
Written by <NAME> and <NAME>
-->

<!DOCTYPE html>
<html data-require="math">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Bubble Sort Proficiency Exercise</title>
  <script src="../../lib/jquery.min.js"></script>
  <script src="../../lib/jquery-ui.min.js"></script>
  <script src="../../JSAV/lib/jquery.transit.js"></script>
  <script src="../../JSAV/lib/raphael.js"></script>
  <script src="../../ODSAkhan-exercises/khan-exercise.js"></script>
  <script src="../../JSAV/build/JSAV-min.js"></script>
  <link rel="stylesheet" href="../../JSAV/css/JSAV.css" type="text/css" />
  <link rel="stylesheet" href="../../lib/odsaStyle-min.css" type="text/css" />
  <link rel="stylesheet" href="GrowthRates.css" type="text/css" />
</head>

<body data-height="550" data-width="950">
<script>
var
  jsav,           // The JSAV object
  answerArr = [], // The (internal) array that stores the correct answer
  cloneArr = [],  // A copy of the (internal) array at the start of the exercise for reset
  functions = [],
  jsavArr,        // The array that the user manipulates (JSAV object)
  userInput,      // Boolean: Tells us if user ever did anything
  selected_index; // Position that has been selected by user for swap

// Click event handler on the array
var clickHandler = function (index, e) {
  if (selected_index === -1) { // if nothing currently selected
    jsavArr.css(index, {"font-size": "130%"});
    selected_index = index;
  }
  else {
    jsavArr.swap(selected_index, index);
    jsavArr.css(index, {"font-size": "100%"});
    jsavArr.css(selected_index, {"font-size": "100%"});
    selected_index = -1;  // Reset to nothing selected
  }
  userInput = true;
};

// reset function definition
var f_reset = function () {
  jsavArr.clear();             // Re-initialize the displayed array object
  jsavArr = jsav.ds.array(cloneArr, {indexed: false, center: false});
  jsavArr.click(clickHandler); // Rebind click handler after reset
  userInput = false;
  selected_index = -1;         // Reset to nothing selected
};

// swap two values in array
var swap = function (arr, i, j) {
  var temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
};

// Initialise the exercise
var initJSAV = function (arr_size) {
  var i, j;
  userInput = false;
  selected_index = -1;
  functions = ["<code>\\log{\\log{n}}</code>", 
                 "<code>\\sqrt{\\log{n}}</code>",
                 "<code>\\log{n}</code>",
                 "<code>\\log^2{n}</code>",
                 "<code>n\\log{n}</code>",
                 "<code>n\\log^2{n}</code>",
                 "<code>n^{\\log{n}}</code>",
                 "<code>n^{4/3}</code>",
                 "<code>n^2</code>",
                 "<code>2^\\sqrt{n}</code>",
                 "<code>2^n</code>",
                 "<code>2^{n^2}</code>"
                 ];
  answerArr.length = 0; // Out with the old

  jsav = new JSAV("jsav");
  jsav.recorded();
  randomize(arr_size);
  jsavArr = jsav.ds.array(answerArr, {indexed: false, center: false});
  // Now make a copy
  cloneArr = answerArr.slice(0);

  // Compute the correct Answer
  for (i = 0; i < arr_size - 1; i++) {
    for(j = 1; j < arr_size - i; j++)
    if (functions.indexOf(answerArr[j-1]) > functions.indexOf(answerArr[j])) {
      swap(answerArr, j-1, j);
    }
  }

  // Bind the clickHandler to handle click events on the array
  jsavArr.click(clickHandler);
  // Set up handler for reset button<commit_msg>Fixing ordering<commit_after><!--
Bubble Sort mini-proficiency exercise.
Written by <NAME> and <NAME>
-->

<!DOCTYPE html>
<html data-require="math">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Bubble Sort Proficiency Exercise</title>
  <script src="../../lib/jquery.min.js"></script>
  <script src="../../lib/jquery-ui.min.js"></script>
  <script src="../../JSAV/lib/jquery.transit.js"></script>
  <script src="../../JSAV/lib/raphael.js"></script>
  <script src="../../ODSAkhan-exercises/khan-exercise.js"></script>
  <script src="../../JSAV/build/JSAV-min.js"></script>
  <link rel="stylesheet" href="../../JSAV/css/JSAV.css" type="text/css" />
  <link rel="stylesheet" href="../../lib/odsaStyle-min.css" type="text/css" />
  <link rel="stylesheet" href="GrowthRates.css" type="text/css" />
</head>

<body data-height="550" data-width="950">
<script>
var
  jsav,           // The JSAV object
  answerArr = [], // The (internal) array that stores the correct answer
  cloneArr = [],  // A copy of the (internal) array at the start of the exercise for reset
  functions = [],
  jsavArr,        // The array that the user manipulates (JSAV object)
  userInput,      // Boolean: Tells us if user ever did anything
  selected_index; // Position that has been selected by user for swap

// Click event handler on the array
var clickHandler = function (index, e) {
  if (selected_index === -1) { // if nothing currently selected
    jsavArr.css(index, {"font-size": "130%"});
    selected_index = index;
  }
  else {
    jsavArr.swap(selected_index, index);
    jsavArr.css(index, {"font-size": "100%"});
    jsavArr.css(selected_index, {"font-size": "100%"});
    selected_index = -1;  // Reset to nothing selected
  }
  userInput = true;
};

// reset function definition
var f_reset = function () {
  jsavArr.clear();             // Re-initialize the displayed array object
  jsavArr = jsav.ds.array(cloneArr, {indexed: false, center: false});
  jsavArr.click(clickHandler); // Rebind click handler after reset
  userInput = false;
  selected_index = -1;         // Reset to nothing selected
};

// swap two values in array
var swap = function (arr, i, j) {
  var temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
};

// Initialise the exercise
var initJSAV = function (arr_size) {
  var i, j;
  userInput = false;
  selected_index = -1;
  functions = ["<code>\\log{\\log{n}}</code>", 
                 "<code>\\sqrt{\\log{n}}</code>",
                 "<code>\\log{n}</code>",
                 "<code>\\log^2{n}</code>",
                 "<code>n\\log{n}</code>",
                 "<code>n\\log^2{n}</code>",
                 "<code>n^{4/3}</code>",
                 "<code>n^2</code>",
				 "<code>n^{\\log{n}}</code>",
                 "<code>2^\\sqrt{n}</code>",
                 "<code>2^n</code>",
                 "<code>2^{n^2}</code>"
                 ];
  answerArr.length = 0; // Out with the old

  jsav = new JSAV("jsav");
  jsav.recorded();
  randomize(arr_size);
  jsavArr = jsav.ds.array(answerArr, {indexed: false, center: false});
  // Now make a copy
  cloneArr = answerArr.slice(0);

  // Compute the correct Answer
  for (i = 0; i < arr_size - 1; i++) {
    for(j = 1; j < arr_size - i; j++)
    if (functions.indexOf(answerArr[j-1]) > functions.indexOf(answerArr[j])) {
      swap(answerArr, j-1, j);
    }
  }

  // Bind the clickHandler to handle click events on the array
  jsavArr.click(clickHandler);
  // Set up handler for reset button
{'fraction_non_alphanumeric': 0.18769581315864425, 'fraction_numerical': 0.010253489034463116, 'mean_word_length': 2.6502079002079, 'pattern_counts': {'":': 6, '<': 109, '<?xml version=': 0, '>': 107, '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': '3816389', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2330, 'n_words': 580}