Manage your digital spending effortlessly with the Rewarble VISA USD 70 Gift Card! This virtual Visa card allows you to make payments on various platforms, offering the flexibility of reloading or one-time use. Enjoy the safety of a gift card without the need for a credit card. Perfect for gifting, this card is usable globally, but please note it does not support 3D secure payments. For more details, visit our terms and conditions page.
To solve this problem, we need to reformat a given array of system requirements into a structured HTML format. Each system (e.g., Windows, Mac, Linux) has its own set of requirements, which are provided as HTML strings. Our task is to parse these strings and present them in a consistent and readable format.
### Approach
1. **Extract and Structure Data**: For each system, extract the requirements from the provided HTML string. Each requirement is typically listed within `
` tags, with the key enclosed in `` tags and the value as plain text.
2. **DOM Parsing**: Use a temporary DOM element to parse the HTML string and extract the individual requirement items. This allows us to handle nested elements and ensures reliable extraction of keys and values.
3. **Construct Output HTML**: For each system, create a structured HTML block with a heading, a minimum specs paragraph, and an unordered list of requirements. Each requirement is formatted with the key wrapped in a `` tag followed by its value.
### Solution Code
```javascript
const requirements = [
{
"system": "Windows",
"requirement": "\n- OS: Windows 7 or higher
\n- Processor: 1.5 GHz
\n- Memory: 2 GB RAM
\n- Graphics: 256MB DirectX 9 or higher
\n- Storage: 1 GB available space
\n- Additional Notes: A printed copy of the Bomb Defusal Manual or an additional web-enabled device to view the Bomb Defusal Manual is required. The Bomb Defusal Manual is freely available at www.bombmanual.com. HTC Vive or Oculus Rift/DK2 required for VR play. Gamepad or motion controllers required for VR play.
\n
"
},
{
"system": "Mac",
"requirement": "\n- OS: macOS 10.15 or higher
\n- Processor: 2 GHz Intel Processor
\n- Memory: 4 GB RAM
\n- Graphics: Integrated Graphics with at least 128MB
\n- Storage: 1.5 GB available space
\n- Additional Notes: A web-enabled device to view the Bomb Defusal Manual is required. Virtual reality not supported on Mac.
\n
"
}
];
const result = [];
requirements.forEach(systemReq => {
const systemDiv = document.createElement('div');
systemDiv.className = 'prod-spec';
// Creating the heading
const heading = document.createElement('h4');
heading.textContent = `${systemReq.system} System Requirements`;
systemDiv.appendChild(heading);
// Adding line break and min specs paragraph
const br = document.createElement('br');
systemDiv.appendChild(br);
const minSpecs = document.createElement('p');
minSpecs.innerHTML = 'MINIMUM SPECS';
systemDiv.appendChild(minSpecs);
// Processing requirements
const ul = document.createElement('ul');
// Parse the requirement HTML string
const tempDiv = document.createElement('div');
tempDiv.innerHTML = systemReq.requirement;
const lis = tempDiv.querySelectorAll('li');
lis.forEach(li => {
const liElement = document.createElement('li');
// Extract key and value
const strong = li.querySelector('strong');
const key = strong.textContent + ':';
const value = li.textContent.replace(strong.textContent + ': ', '');
const span = document.createElement('span');
span.textContent = key;
liElement.appendChild(span);
liElement.appendChild(document.createTextNode(value));
ul.appendChild(liElement);
});
systemDiv.appendChild(ul);
result.push(systemDiv);
});
// Convert the resulting nodes to HTML string
const htmlStrings = result.map(node => {
const container = document.createElement('div');
container.appendChild(node);
return container.innerHTML;
});
// Combine all HTML strings
const finalOutput = htmlStrings.join('');
// Output the final HTML
document.getElementById('output').innerHTML = finalOutput;
```
### Explanation
1. **Data Extraction**: Each system's requirements are extracted from the input array. The requirements are provided as HTML strings, which are parsed using a temporary DOM element to correctly handle nested structures.
2. **DOM Parsing**: The HTML string is loaded into a temporary DOM element to extract individual list items (``). Each list item is processed to separate the key (within `` tags) and the value.
3. **HTML Construction**: For each system, a new HTML structure is created. This structure includes a heading, a minimum specs paragraph, and an unordered list where each requirement is formatted with the key and value as specified.
4. **Output**: The constructed HTML for each system is appended to the output container, resulting in a well-formatted and organized presentation of system requirements.
This approach ensures that the system requirements are presented in a consistent and user-friendly format, making it easier for users to read and understand the specifications.
-
Purchase a Rewarble Visa voucher.
-
Visit the Rewarble redemption site at www.rewarble.com/redeem.
-
Enter and redeem your 16-digit Rewarble voucher. A virtual Visa card will be created for you on Rewarble.
-
Use the card number, CVV, and expiration date provided to complete your transaction on any site accepting Visa.
分享