-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathpairs.js
47 lines (43 loc) · 1.47 KB
/
pairs.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
/**************************************************************
* pairs(names):
*
* - It accepts an array of names:
* pairs(['Asis', 'Hamsa', 'Fawas', 'Mishmish'])
*
* - It returns a randomized pairing of names:
* [['Mishmish', 'Asis'], ['Fawas', 'Hamsa']]
*
* - It can handle an odd number of names:
* pairs(['Asis', 'Hamsa', 'Fawas', 'Mishmish', 'Hussein'])
* returns [['Mishmish', 'Fawas'], ['Asis', 'Hussein'], ['Hamsa']]
*
* - It returns an empty array if it gets passed an empty array:
* pairs([]) returns []
*
* - It returns an empty array if it gets passed nothing:
* pairs() returns []
****************************************************************/
/**********************************************
* READ ME!!!!
*
* We've included this handy method for you.
* It will remove a random element from an array
* and return it to you.
*
* Example Usage:
*
* let numbers = [1, 2, 3, 4];
* let random = numbers.getRandom(); // randomly returns something from the array. e.g. 3
* console.log(random); // 3 (the random element)
* console.log(numbers); // [1, 2, 4] (missing the random element)
************************************************/
Array.prototype.getRandom = function () {
return this.splice(Math.floor(Math.random() * this.length), 1)[0];
};
function pairs(names) {
// Your code goes here
}
module.exports = pairs;
console.log(
pairs(["Asis", "Hamsa", "Fawas", "Mishmish", "Hussein", "Lailz", "Mr Potato"])
);