Last active
July 2, 2025 00:04
-
-
Save kevin-machship/0eb2a7995eb0a42ee60e09fed6d6c67f to your computer and use it in GitHub Desktop.
Handling multiple dgItems.subDgClasses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getDgClasses = (item) => { | |
if (!item.isDgItem || !item.dgItems) return '' | |
const dgClasses = item.dgItems.map(dg => { | |
let dgClassDisplay = dg.dgClass | |
if (dg.hasSubRisk && dg.subDgClasses && dg.subDgClasses.length > 0) { | |
const subDgClassesString = dg.subDgClasses.map(subDg => subDg.class).join(',') | |
dgClassDisplay += `/${subDgClassesString}` | |
} | |
return dgClassDisplay | |
}); | |
const uniqueDgClasses = Array.from(new Set(dgClasses)).join(' | ') | |
return uniqueDgClasses | |
} | |
// Sample outputs: | |
// 6.1/1 | |
// 6.2/2 | 6.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment