pair people flp

by John Doe

HTML

<div id="output"></div>

JavaScript

const output = document.getElementById('output');
const names = ["AV", "AD", "AE", "EG", "EM", "IK", "IS", "JK", "SF", "TB", "VY", "VE"];

const shuffledArray = shuffle(names);

const groups = chunk(shuffledArray, 2);

groups.forEach(function(e) {
	let entry = document.createElement('div');
			entry.innerText = `${e[0]} paired with ${e[1]}`;
	output.append(entry);
})



/* custom functions */
/* split array into chunks*/
function chunk(arr, size) {
	return Array.from({ length: Math.ceil(arr.length / size) }, (v, i) => arr.slice(i * size, i * size + size));
}
  
/* shuffle randomly*/
function shuffle(array) {
  var currentIndex = array.length,
  temporaryValue,
  randomIndex;

  // while there remain elements to shuffle...
  while (0 !== currentIndex) {

    // pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // and swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }

  return array;
}