forked from JDWaghela/JSDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.js
More file actions
49 lines (45 loc) · 1.24 KB
/
testing.js
File metadata and controls
49 lines (45 loc) · 1.24 KB
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
function calculateTotal(input1, input2) {
let result = input1 + input2;
let data = {type: 'calculateTotal', result};
sendData(data);
}
function calculateVat(input1, input2) {
let result = input1 + input2 + 10;
let data = {type: 'calculateVat', result};
sendData(data);
}
function GetSubTotal(basketProducts) {
let result = GetTotal(basketProducts, 'derivedPriceWithSubTotal');
sendData(result);
}
//Get total of specific key from an array. Note:- pass key in String format!
function GetTotal(products, key) {
if (key) {
var total;
if (products.length > 0) {
total = products.reduce(
(prev, curr) =>
parseFloat(prev) + parseFloat(curr[key] ? curr[key] : 0),
0,
);
}
return total;
} else {
return 0;
}
}
//Get total of specific key from an array. Note:- pass key in String format!
function GetTotalValue(products, key) {
let result=0;
if (key && products?.length > 0) {
result = products.reduce(
(prev, curr) =>
parseFloat(prev) + parseFloat(curr[key] ? curr[key] : 0),
0,
);
}
sendData(result);
}
function sendData(data) {
window.ReactNativeWebView.postMessage(JSON.stringify(data));
}