const array = [
{ text: 'a', style: { bold: true }},
{ text: 'b', style: { bold: true }},
{ text: 'c', style: { italic: true, bold: true }},
{ text: 'd', style: { italic: true }},
{ text: 'e', style: { italic: true }},
{ text: 'f', style: { underline: true }},
]
类似这样的数组,
期望格式化后是这样的
const formatArray = [
{ text: 'ab', style: { bold: true }},
{ text: 'c', style: { italic: true, bold: true }},
{ text: 'de', style: { italic: true }},
{ text: 'f', style: { underline: true }},
]
根据完全相同的style属性将text值拼接, text有顺序要求,就是数组的索引,所以只合并相邻的具有相同style属性的元素。
请大牛们指点迷津!
抛砖引玉,简单写了一下,如有需要,注意加上array和text、style属性是否合法的判断。