-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapping.js
50 lines (43 loc) · 930 Bytes
/
mapping.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 hashCode = function (str) {
var hash = 0, i, chr, len
if (str.length === 0) return hash
for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i)
hash = ((hash << 5) - hash) + chr
hash |= 0// Convert to 32bit integer
}
return Math.abs(parseInt(hash))
}
const mapping = (a, b) => {
console.log(a, b)
let aH = hashCode(a) % 6 + 1
let bH = hashCode(b) % 6 + 1
while (aH === bH) {
bH = hashCode(b + a) % 6 + 1
b = a + '.' + b
}
return [aH, bH]
}
const flightMapping = {
'jet': [1, 0, 0, 0],
'set': [0, 1, 0, 0],
'fly': [0, 0, 1, 0],
'go': [0, 0, 0, 1]
}
const weatherMapping = {
'winter': [1, 0, 0],
'sunny': [0, 1, 0],
'rainy': [0, 0, 1]
}
const occasionMapping = {
'yes': [1, 0, 0, 0],
'1-day': [0, 1, 0, 0],
'2-day': [0, 0, 1, 0],
'default': [0, 0, 0, 1]
}
module.exports = {
mapping,
flightMapping,
weatherMapping,
occasionMapping
}