My task involves processing a text string and an array of blocks, each containing an object representing the offset from the beginning and end of the string. The goal is to create unique blocks by aggregating based on the largest offset. See below for a sample:
let text =
"announcing improvements to the GitHub Actions “New Workflow” experience. Now, when you want to create";
let blocks = [
{
word: "GitHub",
start: "31",
end: "37",
},
{
word: "Now",
start: "73",
end: "76",
},
{
word: "GitHub Actions",
start: "31",
end: "45",
},
{
word: "the GitHub Actions “New Workflow” experience.",
start: "27",
end: "72",
},
];
In the example above, "the GitHub Actions “New Workflow” experience." is the largest word, which includes sub-words like "GitHub" and "GitHub Actions". Therefore, our final set will include the largest word with its start and end offsets, while the other two will be split apart.
Desired output
let finalSplit = [
{
start: "73",
end: "76",
splits: [
{
word: "Now",
start: "73",
end: "76",
},
],
},
{
start: "27",
end: "72",
splits: [
{
word: "GitHub Actions",
start: "31",
end: "45",
},
{
word: "the GitHub Actions “New Workflow” experience.",
start: "27",
end: "72",
},
{
word: "GitHub",
start: "31",
end: "37",
},
],
},
];