forked from defia-soft/CodingCompetition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Javascript.js
106 lines (101 loc) · 1.79 KB
/
Javascript.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
class ContestApplication {
main(args){
// Task 1: Refactor mix method
var input = mix(1000000);
// Task 2: Implement sortAndPrint method
sortAndPrint(input);
return 0;
}
sortAndPrint(){
// TODO You are expected to sort the list in the order of r-g-b
// and print the sorted list
}
mix(i){
// TODO You are expected to refactor mix and convertS methods.
// The main targets are "Efficiency" and "Readibility".
// You are free to change everything.
const j = [];
while (i > 0) {
let s = "#";
let c1 = Math.floor(Math.random() * 16);
var s1 = "";
s1 = convertS(c1);
s += s1;
let c2 = Math.floor(Math.random() * 16);
let s2 = "";
s2 = convertS(c2);
s += s2;
let c3 = Math.floor(Math.random() * 16);
var s3 = "";
s3 = convertS(c3);
s += s3;
let c4 = Math.floor(Math.random() * 16);
let s4 = "";
s4 = convertS(c4);
s += s4;
var c5 = Math.floor(Math.random() * 16);
let s5 = "";
s5 = convertS(c5);
s += s5;
let c6 = Math.floor(Math.random() * 16);
let s6;
s6 = convertS(c6);
s += s6;
j.push(s);
--i;
}
return j;
}
convertS(c1) {
var s1 = "";
if (c1 == 0) {
s1 = "0";
}
if (c1 == 1) {
s1 = "1";
}
if (c1 == 2) {
s1 = "2";
}
if (c1 == 3) {
s1 = "3";
}
if (c1 == 4) {
s1 = "4";
}
if (c1 == 5) {
s1 = "5";
}
if (c1 == 6) {
s1 = "6";
}
if (c1 == 7) {
s1 = "7";
}
if (c1 == 8) {
s1 = "8";
}
if (c1 == 9) {
s1 = "9";
}
if (c1 == 10) {
s1 = "A";
}
if (c1 == 11) {
s1 = "B";
}
if (c1 == 12) {
s1 = "C";
}
if (c1 == 13) {
s1 = "D";
}
if (c1 == 14) {
s1 = "E";
}
if (c1 == 15) {
s1 = "F";
}
return s1;
}
}