<commit_before>/*
  createGames is a function that accepts two arguments
    - players: a list of all the players to be created <Array>
    - tournament: a number representing the tournament the games will be affiliated with. <Number>
*/
exports.createGames = (players, tournament, rounds = 1) => {

  // Handle validation for the first argument here.
  if (!Array.isArray(players)) {
    throw new TypeError('createGames\' first argument must be an array.', 'utilities.js', 6);
  }

  // Handle validation for the second argument next.
  if (typeof tournament !== 'number') {
    throw new TypeError('createGames\' second argument must be a number', 'utilities.js', 6);
  }

  // Then make a copy of the input array.
  let list = players.slice();

  // Create a games array.
  let games = [];

  // While there is something in the copy of the players list,
  while (list.length > 0) {

    // grab the first player from it,
    let p1 = list.pop();

    // and go over each other player and create a game with those two players.
    list.forEach(p2 => {
      // handle some double check validation here.
      if (typeof p2 !== 'number' || typeof p1 !== 'number') {
        throw new TypeError('Items in the array passed to createGames should be numbers', 'utilities.js', 6);
      } else {
        let game = {p1, p2};

        // Set a tournament on the game and push it into the games array.
        game.tournament = tournament;
        games.push(game);
      }
    });
  }

  // applyRounds and return the resulting games array once it is all finished.

  return exports.applyRounds(games, rounds);
};

exports.formatName = (string) => {
  // Handle validation here
  if (typeof string !== 'string') {
    throw new TypeError('input must be a string', 'utilities.js', 49);
  }
  // then take care of the actual formatting here and return it. Capitalize the first letter of the string, and every other letter to lowercase.
  return string.split('').map((char, index) => (
    index === 0 ? char.toUpperCase() : char.toLowerCase()
  )).join('');
};


// ApplyRounds takes the build games array and creates duplicates for the number of rounds asked.
/**
  * ApplyRounds takes the build games array and creates duplicates for the number of rounds asked.
  * @param {array} games - list of created games
  * @param {number} rounds - how many rounds to apply.
*/
exports.applyRounds = (games, rounds) => {
  // combined starts as the input array of games
  let combined = games;

  // for the number of rounds passed in, add the games array to the combined holder
    // and let combined be that result.
  for (let i = 1; i < rounds; i++) {
    combined = combined.concat(games);
  }

  // return the result
  return combined;
};

/**
  * createTable - Just like the client side buildTable. takes two
  * @param {array} players - to have access to their usernames
  * @param {array} games - a list of games to be applied.
*/
exports.createTable = (players, games) => {

  let trackedStats = {
    wins: 0, losses: 0, draws: 0, goalsFor: 0, goalsAgainst: 0, shots: 0, onGoal: 0, reds: 0, yellows: 0, points: 0, goalDiff: 0,<commit_msg>Add comments to formatName, & createGames<commit_after>/**
  * createGames - Creates the game pairing from a list of players for the tournament
  * @param {array} players - a list of all the players to be created
  * @param {number} tournament - the tournament id the games will be affiliated with.
  * @param {number} rounds - how many rounds this tournament will play
*/
exports.createGames = (players, tournament, rounds = 1) => {

  // Handle validation for the first argument here.
  if (!Array.isArray(players)) {
    throw new TypeError('createGames\' first argument must be an array.', 'utilities.js', 6);
  }

  // Handle validation for the second argument next.
  if (typeof tournament !== 'number') {
    throw new TypeError('createGames\' second argument must be a number', 'utilities.js', 6);
  }

  // Then make a copy of the input array.
  let list = players.slice();

  // Create a games array.
  let games = [];

  // While there is something in the copy of the players list,
  while (list.length > 0) {

    // grab the first player from it,
    let p1 = list.pop();

    // and go over each other player and create a game with those two players.
    list.forEach(p2 => {
      // handle some double check validation here.
      if (typeof p2 !== 'number' || typeof p1 !== 'number') {
        throw new TypeError('Items in the array passed to createGames should be numbers', 'utilities.js', 6);
      } else {
        let game = {p1, p2};

        // Set a tournament on the game and push it into the games array.
        game.tournament = tournament;
        games.push(game);
      }
    });
  }

  // applyRounds and return the resulting games array once it is all finished.

  return exports.applyRounds(games, rounds);
};

/**
  * formatName - Capitalizes any name passed to it.
  * @param {string} name - the current table
*/
// Could probably one line this function, but might not be as pretty with comments
exports.formatName = (name) => {
  // Handle validation here
  if (typeof name !== 'string') {
    throw new TypeError('input must be a string', 'utilities.js', 49);
  }
  // then take care of the actual formatting here and return it. Capitalize the first letter of the string, and every other letter to lowercase.
  return name.split('').map((char, index) => (
    index === 0 ? char.toUpperCase() : char.toLowerCase()
  )).join('');
};


/**
  * ApplyRounds takes the build games array and creates duplicates for the number of rounds asked.
  * @param {array} games - list of created games
  * @param {number} rounds - how many rounds to apply.
*/
exports.applyRounds = (games, rounds) => {
  // combined starts as the input array of games
  let combined = games;

  // for the number of rounds passed in, add the games array to the combined holder
    // and let combined be that result.
  for (let i = 1; i < rounds; i++) {
    combined = combined.concat(games);
  }

  // return the result
  return combined;
};

/**
  * createTable - Just like the client side buildTable. takes two
  * @param {array} players - to have access to their usernames
  * @param {array} games - a list of games to be applied.
*/
exports.createTable = (players, games) => {

  let trackedStats = {
    wins: 0, losses: 0, draws: 0, goalsFor: 0, goalsAgainst: 0, shots: 0, onGoal: 0, reds: 0, yellows: 0, points: 0, goalDiff: 0,
{'fraction_non_alphanumeric': 0.11191725841309046, 'fraction_numerical': 0.00802716887928373, 'mean_word_length': 2.9919901417128774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '5789414', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1831, 'n_words': 824}