Become the Slayer in a medieval war against Hell! DOOM: The Dark Ages is the prequel to the critically acclaimed DOOM series, immersing players in the origin story of the DOOM Slayer’s rage. Step into the blood-stained boots of the Slayer and engage in a dark and sinister battle against demonic forces. Armed with powerful weapons like the Super Shotgun and the new Shield Saw, you will fight on demon-infested battlefields, uncovering secrets in id's largest levels to date. Experience the epic cinematic journey and witness the creation of a legend as you take on the legions of Hell.
To solve this problem, we need to reformat HTML content based on given system requirements. The input can be in one of two formats: either as a single system with multiple requirements or as multiple systems each with their own set of requirements. The goal is to generate appropriately structured HTML content for each case.
### Approach
1. **Identify Input Format**: Check if the input array contains objects with a "system" field. If it does, each object represents a separate system. If not, aggregate all requirements into a single system.
2. **Process Each System**: For each system identified:
- Extract the system name and its requirements.
- Parse the requirements from the HTML string provided, extracting each requirement as a key-value pair.
3. **Generate HTML Structure**: Construct the HTML for each system, ensuring it includes the appropriate headings, paragraphs, and lists of requirements.
### Solution Code
```javascript
function reformatRequirements(input) {
if (input.length === 0) return '';
const isSystemCase = 'system' in input[0];
let htmlOutput = '';
if (isSystemCase) {
const systems = [];
input.forEach(systemObj => {
const systemName = systemObj.system;
const requirementHTML = systemObj.requirement;
const parser = new DOMParser();
const doc = parser.parseFromString(requirementHTML, 'text/html');
const lis = doc.querySelectorAll('li');
const requirements = [];
lis.forEach(li => {
const text = li.textContent;
const colonIndex = text.indexOf(':');
if (colonIndex !== -1) {
const key = text.substring(0, colonIndex).trim();
const value = text.substring(colonIndex + 1).trim();
requirements.push({ key, value });
}
});
const systemHTML = `
${systemName} System Requirements
MINIMUM SPECS
${requirements.map(req =>
`- ${req.key}: ${req.value}
`
).join('')}
`;
systems.push(systemHTML);
});
htmlOutput = systems.join('
');
} else {
const requirements = [];
input.forEach(reqObj => {
Object.entries(reqObj).forEach(([key, value]) => {
requirements.push({ key, value });
});
});
htmlOutput = `
PC System Requirements
MINIMUM SPECS
${requirements.map(req =>
`- ${req.key}: ${req.value}
`
).join('')}
`;
}
return htmlOutput;
}
```
### Explanation
1. **Identify Input Format**: The function first checks if the first object in the input array has a "system" field to determine the format.
2. **Process Each System**: For each system, it extracts the requirements HTML, parses it into key-value pairs, and constructs the HTML structure.
3. **Generate HTML Structure**: For each system, it generates the appropriate HTML with headings, paragraphs, and lists. If there are multiple systems, each is separated by line breaks.
This approach ensures that the system requirements are presented in a clear and structured manner, whether they are for a single system or multiple systems.
-
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
Go to this website.
Log into your Microsoft Account.
Enter the key and click Next.
Follow the prompts.
*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.
分享