Dive into the ultimate collection of arcade classics with the MARVEL vs. CAPCOM Fighting Collection! Featuring seven iconic titles, including X-MEN VS. STREET FIGHTER and MARVEL vs. CAPCOM 2, this collection brings back the legendary crossover hits. Enjoy smooth online play, beginner-friendly features, and a treasure trove of artwork and music from the original games. Perfect for both new players and nostalgic fans, this collection is a must-have for any gaming enthusiast!
To solve this problem, we need to reformat a given JSON input into a structured HTML format that clearly presents system requirements. The input can be in one of two forms: either an array of objects where each object contains a single key-value pair (representing different system requirements), or an array of objects where each object contains a 'system' key and a 'requirement' key (which is an HTML string containing multiple requirements).
### Approach
1. **Identify Input Structure**: Check if the input objects contain a 'system' key. If they do, each object represents a different system's requirements. If not, all key-value pairs are part of a single system's requirements.
2. **Parse Requirements**: For each system object, extract the requirements from the 'requirement' string. This involves parsing the HTML string to identify individual requirements.
3. **Generate HTML Structure**: Construct the HTML output by creating a div for each system, including a heading, a paragraph indicating minimum specs, and an unordered list with list items for each requirement.
### Solution Code
```javascript
function reformatHtml(input) {
let output = '';
const hasSystemKey = input.some(obj => obj.hasOwnProperty('system'));
if (hasSystemKey) {
input.forEach(systemObj => {
const system = systemObj.system;
const requirement = systemObj.requirement;
// Parse the requirement HTML to extract key-value pairs
const parser = new DOMParser();
const doc = parser.parseFromString(requirement, 'text/html');
const listItems = doc.querySelectorAll('li');
output += '
';
output += `
${system} System Requirements
`;
output += '
';
output += '
MINIMUM SPECS
';
output += '
';
listItems.forEach(li => {
const keyParts = li.textContent.split(':');
const key = keyParts[0].trim();
const value = keyParts.slice(1).join('').trim();
output += '- ';
output += `${key}:`;
output += `${value}`;
output += '
';
});
output += '
';
output += '
';
output += '
';
output += '
';
});
} else {
const requirements = [];
input.forEach(obj => {
const keys = Object.keys(obj);
keys.forEach(key => {
requirements.push({ key, value: obj[key] });
});
});
output += '
';
output += '
PC System Requirements
';
output += '
';
output += '
MINIMUM SPECS
';
output += '
';
requirements.forEach(req => {
output += '- ';
output += `${req.key}:`;
output += `${req.value}`;
output += '
';
});
output += '
';
output += '
';
}
return output.replace(/\n/g, '');
}
```
### Explanation
1. **Identify Input Structure**: The function first checks if any of the input objects contain a 'system' key to determine if they represent different systems.
2. **Parse Requirements**: For each system object, it parses the 'requirement' string as HTML to extract individual requirements. Each list item in the HTML string is processed to split into key-value pairs.
3. **Generate HTML Structure**: The function constructs the HTML output by creating a div for each system, including a heading, a paragraph, and an unordered list with list items for each requirement. The output is then formatted and returned.
This approach ensures that the system requirements are presented in a clear and structured HTML format, making it easy to read and understand.
-
ON XBOX ONE AND XBOX SERIES X|S:
- Press the Xbox button to open the guide, and then select Store.
- Press the View button to open the side menu, and then select Redeem.
- Enter the 25-character code, select Next, and then follow the prompts.
-
ON XBOX 360*:
- Press the Guide button on your controller.
- Select Games & Apps, and then select Redeem Code.
- Enter the 25-character code, and then follow the prompts to complete your redemption.
-
IN A WEB BROWSER
-
*Please note that Xbox 360 codes can ONLY be activated on the Xbox 360 console directly!
-
*Make sure to activate your Xbox 360 code before July 29, 2024! Due to Xbox 360 store closing the codes will expire after that date. Once activated the game can be downloaded and played on Xbox 360 console after the store is closed.
Seien Sie der Erste, der dieses Produkt bewertet!
Teilen