-
Notifications
You must be signed in to change notification settings - Fork 16
/
a_basics.js
78 lines (73 loc) · 2.09 KB
/
a_basics.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
// Primitive arguments
function calculateCommissionJs(volume) {
var fee, rate, commission, bonus, award;
fee = 0.0;
bonus = 0.0;
if (volume > 200000.0) {
rate = 0.15;
bonus = 1000.0;
} else {
if (volume > 100000.0) rate = 0.123;
else {
if (volume > 50000.0) rate = 0.1;
else {
if (volume >= 10000.0) rate = 0.075;
else {
if (volume >= 5000.0) rate = 0.05;
else {
if (volume > 0.0) rate = 0.025;
else {
rate = 0;
fee = 50.0;
}
}
}
}
}
}
commission = Math.trunc(volume * rate * 100) / 100;
award = commission + bonus - fee;
return Math.trunc(award * 100) / 100;
}
// Structured arguments
function getClientAgeGenerationJs(client){
const res = {
gen: null,
set: true
}
if (client.age <= 18){
res.gen = "Gen.Z"
} else if (client.age > 18 && client.age < 34){
res.gen = "Gen.Y"
} else if (client.age >= 34){
res.gen = "Gen.X"
} else {
res.set = false
}
return res
}
// Structured arguments with deep nesting
function getClientScoreJs(client){
if (client.age.firstname && client.age.lastname){
var total_compliant_volume = 0;
var dates = [];
for (i = 0; i < client.orders.length; i++){
if (client.orders[i].order_id != -1 && client.orders[i].currency === "EUR"){
dates.push(client.orders[i].date)
total_compliant_volume += client.orders[i].volume
}
}
return total_compliant_volume / dates.length
} else {
return 0
}
}
// Regex Inferer
function isEmailValidJs(email) {
if (typeof email !== "string") {
return false;
}
const unicodePattern = /[^\x00-\x7F]/;
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return !unicodePattern.test(email) && re.test(email.toLowerCase());
}