-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.js
54 lines (48 loc) · 1.34 KB
/
launch.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
const solution = require("./maxProductOfThree")
function generateArray(L, odd) {
let arr = []
for (let i = 0 ; i < (L-1)/2 ; i++) {
const val = Math.floor(Math.random() * L)
arr.push(val)
arr.push(val)
}
arr.push(odd)
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array
}
return shuffleArray(arr)
}
function generateArraySmallInt(L, max) {
let arr = []
for (let i = 0 ; i < L; i++) {
arr.push(Math.floor((Math.random()) * max))
}
return arr
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array
}
function generateArrayInt3same(L) {
let arr = []
for (let i = 0 ; i < L / 3; i++) {
arr.push(i, i, i)
}
return shuffleArray(arr)
}
const startTime = new Date().getTime()
// const arr = generateArraySmallInt(10)
// const sol = solution([2, 0, 2, 2, 1, 0])
// const sol = solution([5, 5, 0, 5, 5, 5])
// const sol = solution([9, 5, 7, 3, 2, 7, 3, 1, 10, 8])
// const sol = solution(5, [3, 4, 4, 6, 1, 4, 4])
const sol = solution([-5, 5, -5, 4])
console.log(sol)
console.log(`${(new Date().getTime() - startTime)*.001}s`)