{"id":2631,"date":"2024-11-10T13:41:19","date_gmt":"2024-11-10T05:41:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2631\/"},"modified":"2024-11-10T13:41:19","modified_gmt":"2024-11-10T05:41:19","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-javascript-%e5%b0%86%e6%95%b0%e7%bb%84%e4%b8%ad%e7%9a%84%e6%95%b0%e5%ad%97%e6%8e%92%e5%88%97%e6%88%90%e6%9c%80%e5%a4%a7%e7%9a%84%e6%95%b0%e5%ad%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2631\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 JavaScript \u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u6392\u5217\u6210\u6700\u5927\u7684\u6570\u5b57\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173081685321504.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u6392\u5217\u6210\u6700\u5927\u7684\u6570\u5b57\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u6392\u5217\u6210\u6700\u5927\u7684\u6570\u5b57\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5bf9\u6570\u7ec4\u7684\u6570\u5b57\u8fdb\u884c\uff0c\u4ee5\u751f\u6210\u6700\u5927\u7684\u6570\u5b57\uff1f<\/strong><\/p>\n<p>javascript \u62e5\u6709\u5904\u7406\u6570\u7ec4\u548c\u6570\u5b57\u7684\u5f3a\u5927\u529f\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u529f\u80fd\u6765\u89e3\u51b3\u6392\u5217\u6570\u5b57\u5e76\u751f\u6210\u6700\u5927\u6570\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4e00\u79cd\u6709\u6548\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u9012\u5f52\u7684\u6392\u5217\u7b97\u6cd5\u3002\u8be5\u7b97\u6cd5\u5c06\u9012\u5f52\u5730\u751f\u6210\u6570\u7ec4\u4e2d\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\uff0c\u5e76\u9009\u62e9\u6570\u5b57\u76f8\u8fde\u540e\u80fd\u751f\u6210\u6700\u5927\u503c\u7684\u6392\u5217\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u9012\u5f52\u7684 permutate \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u6570\u7ec4\u548c\u4e00\u4e2a\u5df2\u6392\u5217\u7684\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u3002\u5b83\u5c06\u5f39\u51fa\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u63d2\u5165\u5230\u5df2\u6392\u5217\u6570\u7ec4\u4e2d\u7684\u5404\u4e2a\u4f4d\u7f6e\uff0c\u751f\u6210\u65b0\u7684\u6392\u5217\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e2a orderby \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u4f7f\u7528 permutate \u51fd\u6570\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\uff0c\u5e76\u4ece\u8fd9\u4e9b\u6392\u5217\u4e2d\u9009\u62e9\u80fd\u751f\u6210\u6700\u5927\u503c\u7684\u6392\u5217\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06\u6bcf\u4e2a\u6392\u5217\u4e2d\u7684\u5143\u7d20\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u6bd4\u8f83\u8fd9\u4e9b\u5b57\u7b26\u4e32\u7684\u5b57\u5178\u5e8f\uff0c\u4ee5\u786e\u5b9a\u54ea\u4e2a\u6392\u5217\u751f\u6210\u7684\u6700\u5927\u503c\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8f93\u5165\u6570\u7ec4\u4f20\u9012\u7ed9 orderby \u51fd\u6570\uff0c\u5b83\u5c06\u8fd4\u56de\u6700\u5927\u7684\u6570\u5b57\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<pre>\/\/ \u6392\u5217\nfunction permutate(array, permutatedArray) {\n  if (!permutatedArray) {\n    permutatedArray = [];\n  }\n  if (array.length &gt; 1) {\n    var elementCur = array.shift();\n    permutate(array, permutatedArray);\n    var permutatedArrayLen = permutatedArray.length;\n    for (var j = 0; j &lt; permutatedArrayLen; j++) {\n      var p = permutatedArray.shift();\n      for (var i = 0; i &lt;= p.length; i++) {\n        var r = p.slice(0);\n        r.splice(i, 0, elementCur);\n        permutatedArray.push(r);\n      }\n    }\n  } else {\n    permutatedArray.push([array[0]]);\n  }\n  return permutatedArray;\n}\n\n\/\/ \u6392\u5e8f\nfunction orderBy(arr) {\n  var sort = [];\n  permutate(arr, sort);\n  var max = sort[0].join('');\n  for (var i = 0; i &lt; sort.length; i++) {\n    var item = sort[i].join('');\n    if (max &lt; item) {\n      max = item;\n    }\n  }\n  return max;\n}\n\nvar arr = [2, 8, 9, 35, 38, 86, 211, 380, 384, 3856];\nconsole.log(orderBy(arr)); \/\/ 3856384380211893835862<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u6709\u6548\u5730\u751f\u6210\u4efb\u610f\u4e00\u7ec4\u6570\u5b57\u6240\u80fd\u7ec4\u6210\u7684\u6700\u5927\u503c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 JavaScript \u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u6210\u6700\u5927\u7684\u6570\u5b57\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5bf9\u6570\u7ec4\u7684\u6570\u5b57\u8fdb\u884c\uff0c\u4ee5\u751f\u6210\u6700\u5927\u7684\u6570\u5b57\uff1f javascript \u62e5\u6709\u5904\u7406\u6570\u7ec4\u548c\u6570\u5b57\u7684\u5f3a\u5927\u529f\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u529f\u80fd\u6765\u89e3\u51b3\u6392\u5217\u6570\u5b57\u5e76\u751f\u6210\u6700\u5927\u6570\u7684\u95ee\u9898\u3002 \u4e00\u79cd\u6709\u6548\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u9012\u5f52\u7684\u6392\u5217\u7b97\u6cd5\u3002\u8be5\u7b97\u6cd5\u5c06\u9012\u5f52\u5730\u751f\u6210\u6570\u7ec4\u4e2d\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\uff0c\u5e76\u9009\u62e9\u6570\u5b57\u76f8\u8fde\u540e\u80fd\u751f\u6210\u6700\u5927\u503c\u7684\u6392\u5217\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u9012\u5f52\u7684 permutate \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u6570\u7ec4\u548c\u4e00\u4e2a\u5df2\u6392\u5217\u7684\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u3002\u5b83\u5c06\u5f39\u51fa\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u63d2\u5165\u5230\u5df2\u6392\u5217\u6570\u7ec4\u4e2d\u7684\u5404\u4e2a\u4f4d\u7f6e\uff0c\u751f\u6210\u65b0\u7684\u6392\u5217\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u7136\u540e\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e2a orderby \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u4f7f\u7528 permutate \u51fd\u6570\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\uff0c\u5e76\u4ece\u8fd9\u4e9b\u6392\u5217\u4e2d\u9009\u62e9\u80fd\u751f\u6210\u6700\u5927\u503c\u7684\u6392\u5217\u3002 \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06\u6bcf\u4e2a\u6392\u5217\u4e2d\u7684\u5143\u7d20\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u6bd4\u8f83\u8fd9\u4e9b\u5b57\u7b26\u4e32\u7684\u5b57\u5178\u5e8f\uff0c\u4ee5\u786e\u5b9a\u54ea\u4e2a\u6392\u5217\u751f\u6210\u7684\u6700\u5927\u503c\u3002 \u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8f93\u5165\u6570\u7ec4\u4f20\u9012\u7ed9 orderby \u51fd\u6570\uff0c\u5b83\u5c06\u8fd4\u56de\u6700\u5927\u7684\u6570\u5b57\u3002 \u4ee5\u4e0b\u662f\u4ee3\u7801\u5b9e\u73b0\uff1a \/\/ \u6392\u5217 function permutate(array, permutatedArray) { if (!permutatedArray) { permutatedArray = []; } if (array.length &gt; 1) { var elementCur = array.shift(); permutate(array, permutatedArray); var permutatedArrayLen = permutatedArray.length; for (var j = 0; j &lt; permutatedArrayLen; j++) [&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-2631","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2631","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=2631"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2631\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}