Written while watching tv for Phoebe’s work’s secret Santa. Recorded for next year.

function secretSantaMatchMaker(people) {
  let unmatched = people.slice(),
    pairs = {};

  for(let i = 0; i < people.length; i++) {
    let giver = people[i],
      idx,
      receiver;

    // Don't let a person end up with their own name
    // Do you see the bug in this code? It won't happen often
    do {
      idx = Math.floor(Math.random() * unmatched.length);
      receiver = unmatched[idx];
    } while(giver === receiver)

    unmatched.splice(idx, 1);
    pairs[giver] = receiver
  }

  return pairs;
}

let people = [
  'Meghan',
  'Norbert',
  'Nyasia',
  'Elizabeth',
  'Mariam',
  'Lindsay',
  'Jeff',
  'Phoebe',
];

secretSantaMatchMaker(people);