{"id":5176,"date":"2023-01-05T12:07:54","date_gmt":"2023-01-05T04:07:54","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5176"},"modified":"2023-01-05T12:07:54","modified_gmt":"2023-01-05T04:07:54","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescript%e9%99%a3%e5%88%97%e7%9a%84%e5%80%92%e5%ba%8f%e6%8e%92%e5%ba%8fsortdescending","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescript%e9%99%a3%e5%88%97%e7%9a%84%e5%80%92%e5%ba%8f%e6%8e%92%e5%ba%8fsortdescending\/","title":{"rendered":"\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScript\u9663\u5217\u7684\u5012\u5e8f\u6392\u5e8f(sortDescending)"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u9663\u5217, \u5012\u5e8f\u6392\u5e8f, sortDescending\"><\/p>\n<h1>TypeScript \u9663\u5217\u7684\u5012\u5e8f\u6392\u5e8f(sortDescending)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709\u66f4\u591a\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u4e00\u500b\u529f\u80fd\u5c31\u662f\u53ef\u4ee5\u5c0d\u9663\u5217\u9032\u884c\u5012\u5e8f\u6392\u5e8f\u3002\u5728 TypeScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 sortDescending() \u65b9\u6cd5\u5c0d\u9663\u5217\u9032\u884c\u5012\u5e8f\u6392\u5e8f\u3002<\/p>\n<p><!--more--><\/p>\n<p>sortDescending() \u65b9\u6cd5\u53ef\u4ee5\u5c0d\u9663\u5217\u4e2d\u7684\u5143\u7d20\u9032\u884c\u5012\u5e8f\u6392\u5e8f\uff0c\u4e26\u4e14\u53ef\u4ee5\u6307\u5b9a\u6392\u5e8f\u7684\u6bd4\u8f03\u51fd\u6578\u3002\u6bd4\u8f03\u51fd\u6578\u53ef\u4ee5\u6307\u5b9a\u6392\u5e8f\u7684\u65b9\u5f0f\uff0c\u4f8b\u5982\u6309\u7167\u5b57\u6bcd\u9806\u5e8f\u6216\u6578\u5b57\u5927\u5c0f\u7b49\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff0c\u4f7f\u7528 sortDescending() \u65b9\u6cd5\u5c0d\u9663\u5217\u9032\u884c\u5012\u5e8f\u6392\u5e8f\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet numbers = [5, 1, 4, 2, 3];\n\nnumbers.sortDescending();\n\nconsole.log(numbers); \/\/ [5, 4, 3, 2, 1]\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba numbers \u7684\u9663\u5217\uff0c\u5176\u4e2d\u5305\u542b\u4e86 5 \u500b\u6578\u5b57\uff0c\u7136\u5f8c\u6211\u5011\u4f7f\u7528 sortDescending() \u65b9\u6cd5\u5c0d\u9663\u5217\u9032\u884c\u5012\u5e8f\u6392\u5e8f\uff0c\u6700\u5f8c\u6211\u5011\u4f7f\u7528 console.log() \u65b9\u6cd5\u5c07\u6392\u5e8f\u5f8c\u7684\u9663\u5217\u8f38\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<p>sortDescending() \u65b9\u6cd5\u4e5f\u53ef\u4ee5\u63a5\u53d7\u4e00\u500b\u6bd4\u8f03\u51fd\u6578\uff0c\u4ee5\u6307\u5b9a\u6392\u5e8f\u7684\u65b9\u5f0f\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet names = [\"John\", \"Bob\", \"Alice\", \"Zoe\"];\n\nnames.sortDescending((a, b) => {\n  if (a < b) {\n    return -1;\n  }\n  if (a > b) {\n    return 1;\n  }\n  return 0;\n});\n\nconsole.log(names); \/\/ [\"Zoe\", \"John\", \"Bob\", \"Alice\"]\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba names \u7684\u9663\u5217\uff0c\u5176\u4e2d\u5305\u542b\u4e86 4 \u500b\u5b57\u4e32\uff0c\u7136\u5f8c\u6211\u5011\u4f7f\u7528 sortDescending() \u65b9\u6cd5\u5c0d\u9663\u5217\u9032\u884c\u5012\u5e8f\u6392\u5e8f\uff0c\u4e26\u6307\u5b9a\u6bd4\u8f03\u51fd\u6578\uff0c\u6700\u5f8c\u6211\u5011\u4f7f\u7528 console.log() \u65b9\u6cd5\u5c07\u6392\u5e8f\u5f8c\u7684\u9663\u5217\u8f38\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<p>sortDescending() \u65b9\u6cd5\u53ef\u4ee5\u8b93\u6211\u5011\u8f15\u9b06\u5730\u5c0d\u9663\u5217\u9032\u884c\u5012\u5e8f\u6392\u5e8f\uff0c\u4e26\u4e14\u53ef\u4ee5\u6307\u5b9a\u6392\u5e8f\u7684\u65b9\u5f0f\uff0c\u4f7f\u5f97\u6211\u5011\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u5c0d\u9663\u5217\u9032\u884c\u6392\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aTypeScript\u662f\u4e00\u7a2e\u5f37\u5927\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u7c21\u55ae\u800c\u6709\u6548\u7684\u65b9\u6cd5\u4f86\u5be6\u73fe\u9663\u5217\u7684\u5012\u5e8f\u6392\u5e8f\uff0c\u7a31\u70basortDescending\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528sortDescending\u4f86\u5be6\u73fe\u9663\u5217\u7684\u5012\u5e8f\u6392\u5e8f\uff0c\u4ee5\u53ca\u5b83\u7684\u512a\u9ede\u548c\u7f3a\u9ede\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5176","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1lu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5176"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5176\/revisions"}],"predecessor-version":[{"id":5177,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5176\/revisions\/5177"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}