<commit_before>function manda(data, capacity) {
  let returnData = [];
  let mandatories = [];
  let freebies = [];

  data.forEach((obj) => {
    if (obj.mandatory) mandatories.push(obj);
    else freebies.push(obj);
  });
  mandatories = mandatories.sort(function(a, b){
    return a.credits > b.credits;
  });
  console.log("mandatories are: ", mandatories);
  while (capacity > 0) {
    for (let i = mandatories.length; i >= 0; i--) {
      console.log(mandatories[i]);
      // if (mandatories[i].hours < capacity) {
      //   returnData.push(mandatories[i]);
      //   capacity -= mandatories[i].capacity;
      // }
    }
    for (let i = 0; i < freebies.length; i++) {
      if (freebies[i].hours < capacity) {
        returnData.push(freebies[i]);
        capacity -= freebies[i].capacity;
      }
    }
  }
  console.log(returnData);
  return returnData;
}

export default manda;<commit_msg>Made mandatory sort algorithm which prioritieses mandatory courses.<commit_after>/**
 * Manda algorithm (Short for mandatory)
 * Prioritieses mandatory courses over optional courses.
 * First populates the courses with as many mandatory
 * courses as possible and then fills all
 * the remaining capacity with optional ones.
 *
 * Starts with the largest mandatory course,
 * because if a course is mandatory and there is
 * capacity for it it should be picked.
 */

function manda(data, capacity) {
  let returnData = [];
  let mandatories = [];
  let freebies = [];

  data.forEach((obj) => {
    if (obj.mandatory) mandatories.push(obj);
    else freebies.push(obj);
  });
  mandatories = mandatories.sort(function(a, b){
    return a.credits > b.credits;
  });

  while (capacity > 0) {
    for (let i = mandatories.length - 1; i >= 0; i--) {
      if (mandatories[i].hours <= capacity) {
        returnData.push(mandatories[i]);
        capacity = capacity - mandatories[i].hours;
      } else break;
    }
    for (let i = 0; i < freebies.length; i++) {
      if (freebies[i].hours <= capacity) {
        returnData.push(freebies[i]);
        capacity = capacity - freebies[i].hours;
      } else break;
    }
  }
  return returnData;
}

export default manda;
{'fraction_non_alphanumeric': 0.1392988929889299, 'fraction_numerical': 0.0032287822878228783, 'mean_word_length': 2.8940754039497305, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4843901', 'n_tokens_mistral': 718, 'n_tokens_neox': 669, 'n_words': 183}