I have the following JsonData:
{
"text": "This is the text with many words",
"annotation": [{
"comment": "Comment A",
"indices": [0, 3]
},
{
"comment": "Comment B",
"indices": [1, 2, 4]
}
]
}
I'd like to color words that belong to each comment so that
"This", "text" ---> Red
and
"is", "the", "with" ---> blue.
I think it requires some filter or map function but I can't imagine it so I ask for a suggestion on how to "iterate" over words, and then over comments, and then over indices. (or maybe in a different order?)
I'd like to do it in React app. Is this the correct place for these calculations?
Code:
export default function PrettyPrint({ jsonData }) {
return (
<div>
{jsonData && jsonData.text.split(' ').map((line) => (
line
// Should the function that filters words for each color be here?
))}
</div>
)
}
I am new to javascript, react, and functional programming so any suggestions will be helpful, thanks.