{"id":50399,"date":"2024-12-03T13:29:06","date_gmt":"2024-12-03T05:29:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50399\/"},"modified":"2024-12-03T13:29:06","modified_gmt":"2024-12-03T05:29:06","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e4%b8%80%e4%b8%aa%e6%8c%89-start-%e5%8d%87%e5%ba%8f%e6%8e%92%e5%88%97%e7%9a%84%e6%95%b0%e7%bb%84%e8%bf%9b%e8%a1%8c%e5%90%88%e5%b9%b6%ef%bc%8c%e5%90%88%e5%b9%b6%e6%9d%a1","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50399\/","title":{"rendered":"\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f<\/h1>\n<p>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241119\/1731980403673bec73f2168.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u63d0\u53d6\u8fde\u7eed\u76f8\u540c\u9879\u5408\u5e76\u7b97\u6cd5\u95ee\u9898<\/strong><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5305\u542b start\u3001end \u548c content\u3002\u76ee\u6807\u662f\u63d0\u53d6\u51fa\u8fde\u7eed\u4e14\u76f8\u540c\u7684\u9879\uff0c\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u5e76\u63d2\u5165\u539f\u6570\u7ec4\u4e2d\u3002\u5408\u5e76\u7684\u6761\u4ef6\u662f start \u548c end \u8fde\u7eed\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre>[\n    { \"start\": 1, \"end\": 2, \"content\": [ \"a\", \"b\", \"e\" ] },    \/\/0\n    { \"start\": 2, \"end\": 3, \"content\": [ \"b\", \"c\" ] },        \/\/1\n    { \"start\": 3, \"end\": 4, \"content\": [ \"b\", \"d\" ] },        \/\/2\n    { \"start\": 4, \"end\": 5, \"content\": [ \"d\" ] },            \/\/3\n    { \"start\": 7, \"end\": 8, \"content\": [ \"b\" ] },            \/\/4\n    { \"start\": 9, \"end\": 11, \"content\": [ \"b\", \"c\" ] }        \/\/5\n]<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>[\n    { \"start\": 1, \"end\": 2, \"content\": [ \"a\", \"e\" ] },\n    { \"start\": 1, \"end\": 4, \"content\": [ \"b\" ] },\n    { \"start\": 2, \"end\": 3, \"content\": [ \"c\" ] },\n    { \"start\": 3, \"end\": 5, \"content\": [ \"d\" ] },\n    { \"start\": 7, \"end\": 8, \"content\": [ \"b\" ] },\n    { \"start\": 9, \"end\": 11, \"content\": [ \"b\", \"c\" ] }\n]<\/pre>\n<p><strong>\u7b97\u6cd5<\/strong><\/p>\n<ol>\n<li>\u904d\u5386\u539f\u6570\u7ec4\uff0c\u5e76\u904d\u5386\u6bcf\u4e2a\u5bf9\u8c61\u7684 content \u6570\u7ec4\u3002<\/li>\n<li>\u5982\u679c\u5f53\u524d\u5bf9\u8c61\u7684 end \u548c\u4e0b\u4e00\u4e2a\u5bf9\u8c61\u7684 start \u76f8\u7b49\uff0c\u4e14\u4e0b\u4e00\u4e2a\u5bf9\u8c61\u7684 content \u6570\u7ec4\u4e2d\u5305\u542b\u5f53\u524d\u5bf9\u8c61\u7684\u5f53\u524d\u9879\uff0c\u5219\u5408\u5e76\u4e0b\u4e00\u4e2a\u5bf9\u8c61\u4e2d\u7684\u5f53\u524d\u9879\u5e76\u66f4\u65b0 end\u3002<\/li>\n<li>\u5bf9\u4e8e\u6bcf\u4e2a\u5408\u5e76\u540e\u7684\u8fde\u7eed\u9879\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u5e76\u5c06\u5176\u63d2\u5165\u539f\u6570\u7ec4\u3002<\/li>\n<li>\u6839\u636e start \u548c end \u91cd\u65b0\u6392\u5e8f\u539f\u6570\u7ec4\u3002<\/li>\n<li>\u6700\u540e\uff0c\u5220\u9664 content \u957f\u5ea6\u4e3a 0 \u7684\u7a7a\u5bf9\u8c61\u3002<\/li>\n<\/ol>\n<p><strong>\u5b9e\u73b0<\/strong><\/p>\n<pre>let arr = [\n    { \"start\": 1, \"end\": 2, \"content\": [ \"A\", \"B\", \"E\" ] },\n    { \"start\": 2, \"end\": 3, \"content\": [ \"B\", \"C\" ] },\n    { \"start\": 3, \"end\": 4, \"content\": [ \"B\", \"D\" ] },\n    { \"start\": 4, \"end\": 5, \"content\": [ \"D\" ] },\n    { \"start\": 7, \"end\": 8, \"content\": [ \"B\" ] },\n    { \"start\": 9, \"end\": 11, \"content\": [ \"B\", \"C\" ] }\n]\n\nlet obj = {}\nlet list = arr.reduce((list, item, index, arr) =&gt; {\n    item.content.forEach(citem =&gt; {\n        let i = index\n        let next, cindex\n        while ((next = arr[i + 1]) &amp;&amp; arr[i].end === next.start &amp;&amp; (cindex = next.content.indexOf(citem)) &gt;= 0) {\n            i++\n            next.content.splice(cindex, 1)\n        }\n        let end = arr[i].end\n        let key = item.start + '-' + end\n        if(!obj[key]){\n            list.push(obj[key] = {\n                start: item.start,\n                end,\n                content: [citem]\n            })\n        }else{\n            obj[key].content.push(citem)\n        }\n    })\n    return list\n}, [])\n\nconsole.log(list)<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f \u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u300a\u5982\u4f55\u5c06\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u8fdb\u884c\u5408\u5e76\uff0c\u5408\u5e76\u6761\u4ef6\u4e3a start \u548c end \u8fde\u7eed\u4e14 content \u5305\u542b\u76f8\u540c\u9879\uff1f\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01 \u63d0\u53d6\u8fde\u7eed\u76f8\u540c\u9879\u5408\u5e76\u7b97\u6cd5\u95ee\u9898 \u7ed9\u5b9a\u4e00\u4e2a\u6309 start \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5305\u542b start\u3001end \u548c content\u3002\u76ee\u6807\u662f\u63d0\u53d6\u51fa\u8fde\u7eed\u4e14\u76f8\u540c\u7684\u9879\uff0c\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u5e76\u63d2\u5165\u539f\u6570\u7ec4\u4e2d\u3002\u5408\u5e76\u7684\u6761\u4ef6\u662f start \u548c end \u8fde\u7eed\u3002 \u793a\u4f8b \u8f93\u5165\uff1a [ { &#8220;start&#8221;: 1, &#8220;end&#8221;: 2, &#8220;content&#8221;: [ &#8220;a&#8221;, &#8220;b&#8221;, &#8220;e&#8221; ] }, \/\/0 { &#8220;start&#8221;: 2, &#8220;end&#8221;: 3, &#8220;content&#8221;: [ &#8220;b&#8221;, &#8220;c&#8221; ] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-50399","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=50399"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50399\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}