<commit_before>$(document).ready(function(){
  // initialize common variables
  var operatorExists = false; // status of operator in history
  var equalsExists = false; // status of equals sign in history

  // Read in button presses (types: clear, square/operator, number, dec, sign, equals)
  // Listen for signal: CLEAR
  listenForClear();
  // Listen for signal: number 0-9
  listenForNumber();
  // Listen for signal: DECIMAL
  listenForDecimal();
  // Listen for signal: operator +-*/
  listenForOperator();
  // Listen for signal: SIGN
  listenForSign();
  // Listen for signal: EQUALS
  listenForEquals();
  // Listen for signal: SQUARED
  listenForSquared();

  // display result

  // clear on click

});

// note: key codes reference: https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
// TO DO: will need to visually denote button presses somehow when keyboard is used
// TO DO: Add visualizations..
// TO DO: Add notes/popups? with tips, like ESC will also reset

// CLEAR =======================================================================
function listenForClear(){
  // keyboard: ESC keyboard
  $(document).on('keyup', function(event){
    var charCode = (typeof event.which == "number") ? event.which : event.keyCode;
    if (charCode===27){
      console.log("Key pressed (ESC): CLEAR"); // debug
      clear();
    }
  });
  // mouse click
  $("#clear").on('click', function(){
    console.log("Button pressed: CLEAR"); // debug
    clear();
  });
}

function clear(){
  $("#history").html("");   // clear history
  $("#result").html("0");   // clear history
  return 0;
}

// NUMBER ======================================================================
function listenForNumber(){
  // keyboard: ESC keyboard
  $(document).on('keyup', function(event){
    var charCode = (typeof event.which == "number") ? event.which : event.keyCode;
    if (charCode>=48 && charCode<=57 && event.shiftKey===false){
      var digit = charCode-48;
      console.log("Keyboard pressed (digit): " + digit); // debug
      numberPressed(digit);
      digit = NaN;
    } else if(charCode>=96 && charCode<=105){ // numpad
      var digit = charCode-96;
      console.log("Keyboard pressed (digit, numpad): " + digit); // debug
      numberPressed(digit);
      digit = NaN;
    }
  });
  // mouse click
  $(".digit").on('click', function(){
    var digit = this.value;
    console.log("Button pressed (digit): " + digit); // debug
    numberPressed(digit);
    digit = NaN;
  });
}

function numberPressed(digit){

};

// If button is a number 0-9
  // If there is NOT a 1st operator in the history already...
    // If current number = (0) without decimal point
      // put digit in display replacing 0
    // else if current number != (0),
      // add digit to number on right-hand side
  // If there IS a 1st operator in the history already AND NO (equals) in history...
    // If current number = "0" without decimal point
      // put in display replacing 0
    // else if current number is empty, add in digit
    // else if current number != "0" and not empty,
      // add digit to number on right-hand side
  // If there's already an (equals) in the history and no (ansHistory)...
    // If current number = empty or (0) without decimal point
      // add the current (ans) on display to the history...
      // put digit in display replacing 0
    // else if current number != (0),
      // add digit to (display) number on right-hand side

// DECIMAL =====================================================================
function listenForDecimal(){
  // keyboard: ESC keyboard
  $(document).on('keyup', function(event){
    var charCode = (typeof event.which == "number") ? event.which : event.keyCode;
    if ((charCode===190 && event.shiftKey===false) || charCode===110){
      console.log("Key pressed (.): DECIMAL POINT"); // debug
      decimalPoint();
    }
  });
  // mouse click
  $("#decimal").on('click', function(){<commit_msg>Program states stored in a main object passed to functions<commit_after>$(document).ready(function(){
  // initialize common variables
  var state = {};
  state.operatorExists = false; // status of operator in history
  state.equalsExists = false; // status of equals sign in history
  state.history = "";
  state.display = "0";

  // Read in button presses (types: clear, square/operator, number, dec, sign, equals)
  // Listen for signal: CLEAR
  listenForClear();
  // Listen for signal: number 0-9
  listenForNumber(state);
  // Listen for signal: DECIMAL
  listenForDecimal();
  // Listen for signal: operator +-*/
  listenForOperator();
  // Listen for signal: SIGN
  listenForSign();
  // Listen for signal: EQUALS
  listenForEquals();
  // Listen for signal: SQUARED
  listenForSquared();

  // display result

  // clear on click

});

// note: key codes reference: https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
// TO DO: will need to visually denote button presses somehow when keyboard is used
// TO DO: Add visualizations..
// TO DO: Add notes/popups? with tips, like ESC will also reset

// CLEAR =======================================================================
function listenForClear(){
  // keyboard: ESC keyboard
  $(document).on('keyup', function(event){
    var charCode = (typeof event.which == "number") ? event.which : event.keyCode;
    if (charCode===27){
      console.log("Key pressed (ESC): CLEAR"); // debug
      clear();
    }
  });
  // mouse click
  $("#clear").on('click', function(){
    console.log("Button pressed: CLEAR"); // debug
    clear();
  });
}

function clear(){
  $("#history").html("");   // clear history
  $("#result").html("0");   // clear history
  return 0;
}

// NUMBER ======================================================================
function listenForNumber(state){
  // keyboard: ESC keyboard
  $(document).on('keyup', function(event){
    var charCode = (typeof event.which == "number") ? event.which : event.keyCode;
    if (charCode>=48 && charCode<=57 && event.shiftKey===false){
      var digit = charCode-48;
      console.log("Keyboard pressed (digit): " + digit); // debug
      numberPressed(digit,state);
      digit = NaN;
    } else if(charCode>=96 && charCode<=105){ // numpad
      var digit = charCode-96;
      console.log("Keyboard pressed (digit, numpad): " + digit); // debug
      numberPressed(digit,state);
      digit = NaN;
    }
  });
  // mouse click
  $(".digit").on('click', function(){
    var digit = this.value;
    console.log("Button pressed (digit): " + digit); // debug
    numberPressed(digit,state);
    digit = NaN;
  });
}

function numberPressed(digit,state){
  // If there is NOT a 1st operator in the history already...
  if(state.operatorExists===false){
    // If display number = (0) without decimal point
    if(state.display==0){ // string or number is fine
      // put digit in display replacing 0

    }
    // else if current number != (0),
      // add digit to number on right-hand side
  }
  else if(state.operatorExists===true && state.equalsExists===false){
    // If there IS a 1st operator in the history already AND NO (equals) in history...
      // If current number = "0" without decimal point
        // put in display replacing 0
      // else if current number is empty, add in digit
      // else if current number != "0" and not empty,
        // add digit to number on right-hand side
  }
  else if(state.operatorExists===true && state.equalsExists===false){
    // If there's already an (equals) in the history and no (ansHistory)...
      // If current number = empty or (0) without decimal point
        // add the current (ans) on display to the history...
        // put digit in display replacing 0
      // else if current number != (0),
        // add digit to (display) number on right-hand side
  }
};

// DECIMAL =====================================================================
function listenForDecimal(){
  // keyboard: ESC keyboard
  $(document).on('keyup', function(event){
    var charCode = (typeof event.which == "number") ? event.which : event.keyCode;
    if ((charCode===190 && event.shiftKey===false) || charCode===110){
      console.log("Key pressed (.): DECIMAL POINT"); // debug
      decimalPoint();
    }
  });
  // mouse click
  $("#decimal").on('click', function(){
{'fraction_non_alphanumeric': 0.19194823867721064, 'fraction_numerical': 0.00958543014617781, 'mean_word_length': 3.117908238776517, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '555459', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2290, 'n_words': 782}