Enhance your online transactions with the Rewarble PayPal $300 Gift Card! This gift card allows you to easily add funds to your PayPal account, making it ideal for online shopping, gifting, and payments. With a quick and dependable top-up process, you can enjoy secure transactions without directly using your bank account. The card is usable worldwide, ensuring convenience wherever you are. Purchase your Rewarble PayPal Gift Card today and simplify your online payments!
To solve this problem, we need to reformat a given array of system requirements into a structured HTML format. The input can either be a single system with multiple specifications or multiple systems each with their own specifications. The goal is to generate a clean and consistent HTML structure for each system's requirements.
### Approach
1. **Identify the Input Structure**: Check if the input data contains a "system" key to determine if there are multiple systems or just one.
2. **Process Each System**: For each system:
- Create a div with a class "prod-spec".
- Add an h4 heading combining the system name with "System Requirements".
- Include a paragraph with "MINIMUM SPECS" in bold.
- Construct an unordered list (ul) where each list item (li) contains a specification category and its value.
3. **Handle Different Input Types**: If the requirements are provided as key-value pairs, directly extract and format them. If provided as an HTML string, parse the string to extract each specification and format it accordingly.
### Solution Code
```javascript
function reformatHTML(input) {
let output = "";
// Check if input is structured with "system" key
if (input.length > 0 && 'system' in input[0]) {
input.forEach(systemObj => {
const system = systemObj.system;
const requirement = systemObj.requirement;
// Process each requirement as it's provided in HTML format
let processedReq = requirement.replace(/<\/?ul>/g, ''); // Remove ul tags
const lis = processedReq.split('');
const specs = lis
.filter(li => li.trim() !== '')
.map(li => {
const cleanedLi = li.replace(/<\/?li>/g, '').trim();
const strongIndex = cleanedLi.indexOf('');
const category = cleanedLi.substring(8, strongIndex).trim();
const value = cleanedLi.substring(strongIndex + 9).trim();
return { category, value };
});
// Build HTML for this system
output += `
${system} System Requirements
MINIMUM SPECS
`;
specs.forEach(spec => {
output += `-
${spec.category} ${spec.value}
`;
});
output += `
`;
});
} else {
// Single system with specs as key-value pairs
output += `
PC System Requirements
MINIMUM SPECS
`;
input.forEach(specObj => {
const key = Object.keys(specObj)[0];
const value = specObj[key];
output += `-
${key.replace('_', ' ')} ${value}
`;
});
output += `
`;
}
return output.replace(/\n/g, '');
}
```
### Explanation
- **Input Identification**: The function first checks if the input contains a "system" key to determine if there are multiple systems or a single system.
- **System Processing**: For each system, it constructs an HTML structure with the system name, minimum specs paragraph, and an unordered list of specifications.
- **HTML Parsing**: If the requirements are provided as an HTML string, the function parses the string to extract each specification, ensuring the output is correctly formatted.
- **Output Construction**: The function builds the HTML string dynamically, ensuring proper formatting and structure for each system's requirements.
This approach efficiently handles both single and multiple system inputs, ensuring the output is clean, consistent, and properly formatted.
-
Buy a PayPal Rewarble voucher
-
Visit the Rewarble website at www.rewarble.com/redeem
-
Enter your 16-digit Rewarble PayPal Top-Up Card number
-
Provide your PayPal email address
-
Rewarble instantly sends the money to your PayPal account
分享