Gift Me Crypto £400 Gift Card is the perfect way to share the gift of cryptocurrency! This redeemable crypto gift card allows you to instantly gift, reward, or purchase a variety of cryptocurrencies, including Bitcoin, Ethereum, Litecoin, Dogecoin, Binance Coin, USD Coin, Solana, and Matic. Simple and secure, it’s always appreciated by crypto enthusiasts.
To solve this problem, we need to reformat a given JSON input into a structured HTML format. The goal is to create a consistent and user-friendly layout for system requirements, ensuring each system is clearly presented with its respective specifications.
### Approach
The approach involves the following steps:
1. **Iterate Over Each System**: For each system described in the JSON input, create a new section in the HTML output.
2. **Create Structured Elements**: For each system, generate a `div` element with specific classes, an `h4` header, a paragraph for the minimum specs, and an unordered list for the requirements.
3. **Parse Requirements**: Extract each requirement from the input string, split it into a key and a value, and format it into list items within the HTML.
The solution processes the JSON input to ensure each system's requirements are presented in a uniform and readable manner.
### Solution Code
```javascript
function reformatHtml(inputJson) {
let html = "";
const systems = JSON.parse(inputJson);
systems.forEach(system => {
const systemName = system.system || 'PC';
const requirements = system.requirement;
// Create the main div
html += '
';
// Add the header
html += `
${systemName} System Requirements
`;
html += '
';
// Add the minimum specs paragraph
html += '
MINIMUM SPECS
';
// Process each requirement
const parser = new DOMParser();
const doc = parser.parseFromString(requirements, 'text/html');
const lis = doc.querySelectorAll('li');
html += '
';
lis.forEach(li => {
const strong = li.querySelector('strong');
if (strong) {
const key = strong.textContent.trim() + ':';
const value = li.textContent.replace(strong.textContent, '').trim();
html += `- `;
html += `${key}`;
html += `${value}`;
html += `
`;
}
});
html += '
';
html += '
';
});
// Remove the last unnecessary br tags
html = html.replace('
', '
');
return html;
}
```
### Explanation
1. **Parsing Input**: The input JSON is parsed into an array of system objects, each containing a system name and its requirements.
2. **HTML Structure**: For each system, a div with a class `prod-spec` is created. This div includes a header specifying the system, a paragraph for the minimum specs, and a list for the requirements.
3. **Extracting Requirements**: Each requirement string is parsed as HTML. The key is extracted from the `
分享