Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Complete the function getShippingAddressLines so that it returns
- an array of strings that represent the shipping address.
- The format of lines should be:
- <first_name> <last_name>
- <company>
- <address_1>
- <address_2>
- <city>, <province> <postal_code>
- <country_code>
- <phone>
- Any empty line (e.g. if <company> is empty or missing) shouldn't be included in the final array.
- An example of the resulting array:
- [
- 'Arno Willms',
- 'Acme',
- '14433 Kemmer Court',
- 'Suite 369',
- 'New York, NY 10001',
- 'US',
- '1-212-555-1234',
- ]
- */
- interface ShippingAddress {
- company?: string
- first_name: string
- last_name?: string
- address_1: string
- address_2?: string
- city?: string
- country_code?: string
- province?: string
- postal_code?: string
- phone?: string
- }
- function getShippingAddressLines(shippingAddress: ShippingAddress) {
- const lines: string[] = []
- if (!shippingAddress) return lines;
- var Name = shippingAddress.first_name;
- if (shippingAddress.last_name) Name += (" " + shippingAddress.last_name);
- lines.push(Name);
- if (shippingAddress.company) lines.push(shippingAddress.company);
- lines.push(shippingAddress.address_1);
- if (shippingAddress.address_2) lines.push(shippingAddress.address_2);
- var Reg = "";
- if (shippingAddress.city) Reg = shippingAddress.city;
- if (shippingAddress.province)
- {
- if (Reg.length > 0) Reg += ", ";
- Reg += shippingAddress.province;
- }
- if (shippingAddress.postal_code)
- {
- if (Reg.length > 0) Reg += " ";
- Reg += shippingAddress.postal_code;
- }
- if (Reg.length > 0) lines.push(Reg);
- if (shippingAddress.country_code) lines.push(shippingAddress.country_code);
- if (shippingAddress.phone) lines.push(shippingAddress.phone);
- return lines
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement