-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
111 lines (109 loc) · 2.39 KB
/
index.html
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
107
108
109
110
111
<!DOCTYPE html>
<html lang="zh-hans">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>langmask</title>
<script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js"></script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
</head>
<body>
<div id="app">
<input :value="langmask" disabled />
<template v-for="item in CodeLang">
<div v-bind:key="item">
<input type="checkbox" :id="item" :value="item" v-model="value" />
<label :for="item">{{item}}</label>
</div>
</template>
</div>
</body>
<script>
const CodeLang = [
"C",
"C++",
"Pascal",
"Java",
"Ruby",
"Bash",
"Python",
"PHP",
"Perl",
"C#",
"Obj-C",
"FreeBasic",
"Scheme",
"Clang",
"Clang++",
"Lua",
"JavaScript",
"Go",
"SQL(sqlite3)",
"Fortran",
"Matlab(Octave)",
"Cobol",
"R",
"Scratch3"
];
/**
*
* @param {number} mask
* @returns {string[]}
*/
function codeLangMask2Value(mask) {
mask = parseInt(mask, 10);
// 不处理长度超过 mask 的部分
return mask
.toString(2)
.split("")
.reverse()
.map((value, index) => {
if (value === "1") {
return "";
}
return CodeLang[index] || "";
})
.filter(it => it !== "");
}
/**
*
* @param {string[]} value
* @returns {number}
*/
function codeLangValue2Mask(value) {
let ret = 0;
const len = CodeLang.length;
const max = 2 ** len - 1;
for (const it of value) {
const index = CodeLang.findIndex(lang => lang === it);
if (index >= 0) {
ret = ret | (1 << index);
}
}
return max & (ret ^ max);
}
new Vue({
el: "#app",
data() {
return {
value: [],
CodeLang
};
},
computed: {
langmask: function() {
return codeLangValue2Mask(this.value);
}
}
});
</script>
</html>