<commit_before>/* 
Conditions:
- A person cannot receive a gift from herself
- A person cannot receive more than one gift
- A person cannot have more than one wish list

BONUS:
- ability to exclude certain matches (e.g., spouse)

1. Assign Santas
    Given a list of people's names:
    - Iterate over list to select "santa"
    - Remove santa from list
    - Match santa with a random recipient from remaining list
    - Return list of santa and recipient pairs
*/


var matches = [];

function assignSantas(array) {
  if(!array || !array.length) {
    return null;
  }

  var santas      = array.slice();
  var recipients  = array.slice();
  shuffle(recipients);
  

  for(var i=0; i<santas.length; i++) {
    var santa     = santas[i];
    var recipient = recipients[i];
    matches.push({ "santa": santa, "recipient": recipient });
  }

  return matches;
};

function shuffle(array) {
  var n = array.length, 
      i, 
      j;

  while(n) {
    i = Math.floor(Math.random() * n--);

    j = array[n];
    array[n] = array[i];
    array[i] = j;
  } 
  return array;
}

module.exports.assignSantas = assignSantas;<commit_msg>Assign santas round-robin style<commit_after>/* 
Conditions:
- A person cannot receive a gift from herself
- A person cannot receive more than one gift
- A person cannot have more than one wish list

BONUS:
- ability to exclude certain matches (e.g., spouse)

1. Assign Santas
    Given a list of people's names:
    - Iterate over list to select "santa"
    - Remove santa from list
    - Match santa with a random recipient from remaining list
    - Return list of santa and recipient pairs
*/


var matches = [];

function assignSantas(array) {
  if(!array || !array.length) {
    return null;
  }

  var santas      = array.slice();
  shuffle(santas);
  

  for(var i=0; i<santas.length; i++) {
    var santa     = santas[i],
        recipient;

    // Assign santa to the person next to them to avoid assigning to self and avoid duplicate recipients
    if(i !== santas.length-1) {
      recipient = santas[i+1];
    } else {
      recipient = santas[0];      
    }

    matches.push({ "santa": santa, "recipient": recipient });
  }

  return matches;
};

function shuffle(array) {
  var n = array.length, 
      i, 
      j;

  while(n) {
    i = Math.floor(Math.random() * n--);

    j = array[n];
    array[n] = array[i];
    array[i] = j;
  } 

  return array;
}

module.exports.assignSantas = assignSantas;
{'fraction_non_alphanumeric': 0.11651676206050696, 'fraction_numerical': 0.0028618152085036794, 'mean_word_length': 2.6686656671664166, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, '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': '7499683', 'n_tokens_mistral': 839, 'n_tokens_neox': 808, 'n_words': 273}