-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge.dubeed.js
50 lines (41 loc) · 1.24 KB
/
challenge.dubeed.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
const R = require("ramda");
module.exports = {
generate: len => {
const me = module.exports;
const generateArrayTest = R.compose(
me.shuffle,
me.generateArray
);
const arrayTest = generateArrayTest(Number(len));
console.log("Generated " + arrayTest.length + " elements. ");
return arrayTest;
},
generateArray: numberOfElements => {
let array = [];
if (numberOfElements % 2 != 0) numberOfElements++;
const midLen = numberOfElements / 2;
for (let i = 0; i < midLen; i++) {
array[i] = i;
array[midLen + i] = i;
}
const removed = array.splice(
Math.floor(Math.random() * numberOfElements),
1
);
console.log("The answer is: ", removed[0]);
return array;
},
shuffle: a => {
let arrayToShuffle = a.concat();
for (let i = arrayToShuffle.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arrayToShuffle[i], arrayToShuffle[j]] = [
arrayToShuffle[j],
arrayToShuffle[i]
];
}
//console.log("Not dubbed position: " + arrayToShuffle.indexOf(a[a.length-1]));
//console.log("shuffle result: ", arrayToShuffle);
return arrayToShuffle;
}
};