• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Apr 18th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /**
2. * Calculates shipping cost to ship X grams with EMS.
3. * @param {Range} range Range or cell containing the shipping weights.
4. * @param {Number} firstCost Cost of first interval. (Default 20.91)
5. * @param {Number} additionalCost Cost of additional intervals. (Default 6.31)
6. * @param {Number} interval Interval size. (Default 500)
7. * @return Shipping cost in USD.
8. * @customfunction
9. */
10. function EMS_SHIPPING(range, firstCost, additionalCost, interval) {
11.   firstCost = Number(firstCost);
12.
13.   if(isNaN(firstCost)) {
14.      firstCost = 20.91;
15.   }
16.
17.   additionalCost = Number(additionalCost);
18.
19.   if(isNaN(additionalCost)) {
20.      additionalCost = 6.31;
21.   }
22.
23.   interval = Number(interval);
24.
25.   if(isNaN(interval)) {
26.      interval = 500;
27.   }
28.
29.   var totalWeight = 0;
30.
31.   if(typeof range == 'number') {
32.     totalWeight = range;
33.   } else {
34.     for(var i = 0; i < range.length; i++) {
35.       totalWeight += parseFloat(range[i]);
36.     }
37.   }
38.
39.   var totalCost = 0;
40.   var doneFirst = false;
41.
42.   while(totalWeight > 0) {
43.     if(!doneFirst)
44.       totalCost += firstCost;
45.     else
46.       totalCost += additionalCost;
47.
48.     totalWeight -= interval;
49.     doneFirst = true;
50.   }
51.
52.   return totalCost;
53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top