<commit_before>'use strict';
function compareIngredients(ingredients,drinks){
  for(var l=0; l < drinks.length; l++){
    drinks[l].percentMatch = 0;
    drinks[l].match = 0;
  }
  for(var i = 0; i < drinks.length; i++){
      for(var j = 0; j < ingredients.length; j++){
        for(var k = 0; k < drinks[i].ingredients.length; k++){
          if(ingredients[j].ingName.toLowerCase() === drinks[i].ingredients[k][0].toLowerCase()){
            drinks[i].match += 1;
          }
        }
        drinks[i].percentMatch = drinks[i].match / drinks[i].ingredients.length;
      }
  }
  return drinks;
}

function sortByMatch(drinks,amount){
  var drinkSort = [];
  var sortedDrinkArray = [];
  console.log(amount)
  if((amount > 0 || amount =='random') && amount <=drinks.length){
    if(amount === 1){
      console.log('random');
        var drinkSelect = Math.floor(Math.random() * drinkArray.length);
        drinkSort.push([drinkSelect,drinks[drinkSelect].percentMatch]);
        drinkSort.sort(function(a,b){return b[1]-a[1]});
      } else {
        for(var i = 0; i < amount; i++){
          drinkSort.push([i,drinks[i].percentMatch]);
        }
        drinkSort.sort(function(a,b){return b[1]-a[1]});
      }
  } else{
    for(var i = 0; i < drinks.length; i++){
      drinkSort.push([i,drinks[i].percentMatch]);
    }
    drinkSort.sort(function(a,b){return b[1]-a[1]});
  }
  for(var i=0; i < drinkSort.length; i++){
    sortedDrinkArray.push(drinks[drinkSort[i][0]]);
  }
  return sortedDrinkArray;
}

function screenedDrinks(drinks,liquor,category){
  var drinksScreened = [];
  if(liquor !== 'default' && category !=='default'){
    for(var i = 0; i < drinks.length; i++){
      var count = 0;
      for(var j = 0; j < drinks[i].category.length; j++){
        if (drinks[i].baseLiquior.toLowerCase() === liquor.toLowerCase() && drinks[i].category[j].toLowerCase() === category.toLowerCase() && count === 0){
            drinksScreened.push(drinks[i]);}
            count += 1;
          }
      }
  } else if (liquor !== 'default'){
    for(var i = 0; i < drinks.length; i++){
      if (drinks[i].baseLiquior.toLowerCase() === liquor.toLowerCase()){
        drinksScreened.push(drinks[i]);}
    }
  } else if (category !== 'default'){
  for(var i = 0; i < drinks.length; i++){
    var count = 0;
    for(var j = 0; j < drinks[i].category.length; j++){
      if(drinks[i].category[j].toLowerCase() === category.toLowerCase() && count === 0){
      drinksScreened.push(drinks[i]);<commit_msg>adjusted a small error with sorting<commit_after>'use strict';
function compareIngredients(ingredients,drinks){
  for(var l=0; l < drinks.length; l++){
    drinks[l].percentMatch = 0;
    drinks[l].match = 0;
  }
  for(var i = 0; i < drinks.length; i++){
      for(var j = 0; j < ingredients.length; j++){
        for(var k = 0; k < drinks[i].ingredients.length; k++){
          if(ingredients[j].ingName.toLowerCase() === drinks[i].ingredients[k][0].toLowerCase()){
            drinks[i].match += 1;
          }
        }
        drinks[i].percentMatch = drinks[i].match / drinks[i].ingredients.length;
      }
  }
  return drinks;
}

function sortByMatch(drinks,amount){
  var drinkSort = [];
  var sortedDrinkArray = [];
  console.log(amount)
  if((amount > 0 || amount =='random') && amount <=drinks.length){
    if(amount === 1){
      console.log('random');
        var drinkSelect = Math.floor(Math.random() * drinkArray.length);
        drinkSort.push([drinkSelect,drinks[drinkSelect].percentMatch]);
        drinkSort.sort(function(a,b){return b[1]-a[1]});
      } else {
        for(var i = 0; i < amount; i++){
          drinkSort.push([i,drinks[i].percentMatch]);
        }
        drinkSort.sort(function(a,b){return b[1]-a[1]});
      }
  } else{
    for(var i = 0; i < drinks.length; i++){
      drinkSort.push([i,drinks[i].percentMatch]);
    }
    drinkSort.sort(function(a,b){return b[1]-a[1]});
  }
  for(var i=0; i < drinkSort.length; i++){
    sortedDrinkArray.push(drinks[drinkSort[i][0]]);
  }
  return sortedDrinkArray;
}

function screenedDrinks(drinks,liquor,category){
  var drinksScreened = [];
  if(liquor !== 'default' && category !=='default'){
    for(var i = 0; i < drinks.length; i++){
      var countTwoMatch = 0;
      var countOneMatch = 0;
      for(var j = 0; j < drinks[i].category.length; j++){
        console.log(drinks[i].baseLiquior, drinks[i].category[j], i, j, count)
        if (drinks[i].baseLiquior.toLowerCase() === liquor.toLowerCase() && drinks[i].category[j].toLowerCase() === category.toLowerCase() && countTwoMatch === 0){
            drinksScreened.push(drinks[i]);}
            count += 1;
          }
      }
  } else if (liquor !== 'default'){
    for(var i = 0; i < drinks.length; i++){
      if (drinks[i].baseLiquior.toLowerCase() === liquor.toLowerCase()){
        drinksScreened.push(drinks[i]);}
    }
  } else if (category !== 'default'){
  for(var i = 0; i < drinks.length; i++){
    var count = 0;
    for(var j = 0; j < drinks[i].category.length; j++){
      if(drinks[i].category[j].toLowerCase() === category.toLowerCase() && countOneMatch === 0){
      drinksScreened.push(drinks[i]);
{'fraction_non_alphanumeric': 0.19244186046511627, 'fraction_numerical': 0.011821705426356589, 'mean_word_length': 3.0510204081632653, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 5, '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': '3336251', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1804, 'n_words': 336}