Manage your digital spending effortlessly with the Rewarble MasterCard $7 Gift Card! This prepaid Mastercard allows you to make payments across various platforms, offering both safety and flexibility. Whether you choose to reload it or use it once, it functions just like any other Mastercard gift card, eliminating the need for a credit card. Perfect for gifting, the Rewarble card ensures a seamless payment experience.
To solve this problem, we need to reformat a given JSON input into a structured HTML format that clearly presents system requirements. The JSON input can either be a single system requirement or multiple system requirements for different operating systems. The goal is to transform this input into a clean, user-friendly HTML format that follows specific structural guidelines.
### Approach
1. **Identify Input Structure**: Determine if the input JSON contains multiple systems (each with a "system" key) or a single system (without a "system" key).
2. **Handle Multiple Systems**: If the input contains multiple systems, each system's requirements are processed separately, converting HTML strings into individual list items.
3. **Handle Single System**: If the input is a single system, each key-value pair is processed to form the system requirements list.
4. **Construct HTML Structure**: For each system, create a div with a heading, a bold paragraph for "MINIMUM SPECS", and an unordered list where each requirement is listed with a span for the key.
5. **Parse HTML Strings**: If a requirement is given as an HTML string, parse it to extract key-value pairs and format them accordingly.
6. **Output HTML**: Construct the final HTML string following the specified structure, ensuring proper formatting and separation between multiple systems.
### Solution Code
```javascript
// Function to reformat the HTML based on the input structure
function reformatHTML jsonData {
let html = '';
const isMultiSystem = Object.keys(jsonData[0]).includes('system');
// Process multiple systems
if (isMultiSystem) {
for (const sys of jsonData) {
const system = sys.system;
const requirement = sys.requirement;
// Start the prod-spec div
html += `
`;
html += `
${system} System Requirements
`;
html += `
`;
html += `
MINIMUM SPECS
`;
html += `
`;
// Parse the requirement HTML string
const parser = new DOMParser();
const doc = parser.parseFromString(requirement, 'text/html');
const listItems = doc.querySelectorAll('ul li');
for (const li of listItems) {
const strongEls = li.querySelectorAll('strong');
let key = '';
let value = '';
if (strongEls.length > 0) {
key = strongEls[0].textContent;
const textNodes = li.childNodes;
let remainingText = '';
let foundStrong = false;
for (const node of textNodes) {
if (node.nodeType === Node.TEXT_NODE && foundStrong) {
remainingText += node.textContent;
} else if (node.nodeType === Node.ELEMENT_NODE && node.nodeName === 'STRONG') {
foundStrong = true;
}
}
value = remainingText.trim();
}
html += `- `;
html += `${key} ${value}`;
html += `
`;
}
html += `
`;
html += `
`;
html += `
`;
}
} else {
// Process single system
html += `
`;
html += `
PC System Requirements
`;
html += `
`;
html += `
MINIMUM SPECS
`;
html += `
`;
const keyMappings = {
'OS': 'Operating System',
'Processor': 'Processor',
'Memory': 'Memory',
'Graphics': 'Graphics',
'Hard Drive': 'Hard Drive',
'Additional': 'Additional'
};
for (const req of jsonData) {
const key = Object.keys(req)[0];
const value = req[key];
const displayKey = key_mappings[key] || key;
html += `- `;
html += `${displayKey}: ${value}`;
html += `
`;
}
html += `
`;
html += `
`;
}
// Remove the last
if multiple systems are present
if (isMultiSystem && jsonData.length > 1) {
html = html.replace(/(
)+$/, '');
}
return html;
}
```
### Explanation
The solution involves parsing the JSON input to determine if it contains multiple system requirements or a single one. For multiple systems, each requirement string is parsed to extract key-value pairs and formatted into HTML list items. For a single system, key-value pairs are directly converted into the required format. The solution ensures that the output is clean, well-structured HTML, adhering to the specified guidelines.
-
Purchase a Rewarble Mastercard voucher.
-
Visit the Rewarble redemption site at www.rewarble.com/redeem.
-
Enter and redeem your 16-digit Rewarble voucher. A virtual Mastercard will be created for you on Rewarble.
-
Use the card number, CVV, and expiration date provided to complete your transaction on any site accepting Mastercard.
Soyez le premier à donner votre avis sur ce produit !
PARTAGEZ