repl.it
@jonathanbell/

SuperElectronicKeyboardmacro

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
 * The "line" between the two groups is: "below" Sr.
 * Software Dev or "above" Software Dev II. Sorry,
 * not at all trying to be categorical but we need
 * to setup the two groups somehow. The groups can 
 * actually switch after a couple of weeks and mentors
 * can become mentees and vice versa.
 */

const mentors = [
  'Susan',
  'Scott W.',
  'Jo',
];

const mentees = [
  'Jonathan', 
  'Ben',
  'Kayla',
];

function makeFullAssetsMentorshipPairs(mentors, mentees) {
  if (
    (typeof mentors !== 'object' || typeof mentees !== 'object')
    || (mentors.length !== mentees.length)
    || (mentors.length < 1)
  ) {
    console.error('Cannot shuffle/randomize. Check function inputs and totals.');
    return null;
  }
  
  function shuffleArr(array) {
    let currentIndex = array.length;
    let temporaryValue, randomIndex;

    while (0 !== currentIndex) {
      randomIndex = Math.floor(Math.random() * currentIndex);
      currentIndex -= 1;

      temporaryValue = array[currentIndex];
      array[currentIndex] = array[randomIndex];
      array[randomIndex] = temporaryValue;
    }

    return array;
  }
  
  const mentorsShuffled = shuffleArr(mentors);
  const menteesShuffled = shuffleArr(mentees);
  
  return mentorsShuffled.map((m, index) => {
    return { 
      mentor: m,
      mentee: menteesShuffled[index],
    };
  });
}

console.log(makeFullAssetsMentorshipPairs(mentors, mentees));