{"id":6504,"date":"2023-01-08T21:22:46","date_gmt":"2023-01-08T13:22:46","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6504"},"modified":"2023-01-08T21:22:46","modified_gmt":"2023-01-08T13:22:46","slug":"%e4%bd%bf%e7%94%a8react-js%e6%b1%82%e5%8f%96%e6%a8%99%e6%ba%96%e5%b7%ae-2","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%bd%bf%e7%94%a8react-js%e6%b1%82%e5%8f%96%e6%a8%99%e6%ba%96%e5%b7%ae-2\/","title":{"rendered":"\u4f7f\u7528React.JS\u6c42\u53d6\u6a19\u6e96\u5dee"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React, List, \u6807\u51c6\u5dee, standard deviation\"><\/p>\n<h1>\u4f7f\u7528 React.JS \u6c42 List \u7684\u6807\u51c6\u5dee (standard deviation)<\/h1>\n<p>React.JS \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u7aef\u61c9\u7528\u7a0b\u5e8f\u7684 JavaScript \u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u69cb\u5efa\u51fa\u9ad8\u54c1\u8cea\u7684\u7528\u6236\u7aef\u61c9\u7528\u7a0b\u5e8f\u3002\u5728 React.JS \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 List \u7d44\u4ef6\u4f86\u5feb\u901f\u69cb\u5efa\u51fa\u4e00\u500b List\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528\u5b83\u4f86\u6c42\u51fa List \u4e2d\u6578\u64da\u7684\u6807\u51c6\u5dee (standard deviation)\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u6807\u51c6\u5dee (standard deviation)<\/h2>\n<p>\u6807\u51c6\u5dee (standard deviation) \u662f\u4e00\u500b\u7d71\u8a08\u5b78\u4e2d\u7684\u6982\u5ff5\uff0c\u5b83\u8868\u793a\u4e00\u7d44\u6578\u64da\u7684\u5206\u6563\u7a0b\u5ea6\u3002\u5b83\u662f\u4e00\u500b\u6578\u503c\uff0c\u8868\u793a\u4e00\u7d44\u6578\u64da\u7684\u5e73\u5747\u503c\u8207\u6bcf\u500b\u6578\u64da\u4e4b\u9593\u7684\u5dee\u8ddd\u3002\u8f03\u5927\u7684\u6807\u51c6\u5dee\u8868\u793a\u8a72\u7d44\u6578\u64da\u7684\u5206\u6563\u7a0b\u5ea6\u8f03\u5927\uff0c\u8f03\u5c0f\u7684\u6807\u51c6\u5dee\u8868\u793a\u8a72\u7d44\u6578\u64da\u7684\u5206\u6563\u7a0b\u5ea6\u8f03\u5c0f\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 React.JS \u6c42 List \u7684\u6807\u51c6\u5dee (standard deviation)<\/h2>\n<p>\u4f7f\u7528 React.JS \u6c42 List \u7684\u6807\u51c6\u5dee (standard deviation) \u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u4f7f\u7528 List \u7d44\u4ef6\u5c31\u53ef\u4ee5\u5b8c\u6210\u3002\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5b9a\u7fa9\u4e00\u500b List \u7d44\u4ef6\uff0c\u4e26\u5c07 List \u4e2d\u7684\u6578\u64da\u50b3\u5165 List \u7d44\u4ef6\u4e2d\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst List = (props) => {\n  const { data } = props;\n  return (\n    <div>\n      {data.map((item, index) => (\n        <div key={index}>{item}<\/div>\n      ))}\n    <\/div>\n  );\n};\n<\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 List \u7d44\u4ef6\u4f86\u6c42\u51fa List \u4e2d\u6578\u64da\u7684\u6807\u51c6\u5dee (standard deviation)\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst calculateStandardDeviation = (data) => {\n  \/\/ \u8a08\u7b97 List \u4e2d\u6578\u64da\u7684\u5e73\u5747\u503c\n  const mean = data.reduce((acc, cur) => acc + cur, 0) \/ data.length;\n\n  \/\/ \u8a08\u7b97 List \u4e2d\u6578\u64da\u8207\u5e73\u5747\u503c\u4e4b\u9593\u7684\u5dee\u8ddd\n  const diffs = data.map((item) => item - mean);\n\n  \/\/ \u8a08\u7b97 List \u4e2d\u6578\u64da\u8207\u5e73\u5747\u503c\u4e4b\u9593\u7684\u5dee\u8ddd\u7684\u5e73\u65b9\u548c\n  const diffsSquared = diffs.map((diff) => diff * diff);\n  const diffsSquaredSum = diffsSquared.reduce((acc, cur) => acc + cur, 0);\n\n  \/\/ \u8a08\u7b97 List \u4e2d\u6578\u64da\u7684\u6807\u51c6\u5dee\n  const standardDeviation = Math.sqrt(diffsSquaredSum \/ data.length);\n\n  return standardDeviation;\n};\n<\/pre>\n<p>\u6700\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 List \u7d44\u4ef6\u548c calculateStandardDeviation \u51fd\u6578\u4f86\u6c42\u51fa List \u4e2d\u6578\u64da\u7684\u6807\u51c6\u5dee (standard deviation)\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconst data = [1, 2, 3, 4, 5];\nconst standardDeviation = calculateStandardDeviation(data);\n\nReactDOM.render(\n  <List data={data} \/>,\n  document.getElementById('root')\n);\n\nconsole.log(standardDeviation); \/\/ 1.4142135623730951\n<\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 React.JS \u7684 List \u7d44\u4ef6\u548c calculateStandardDeviation \u51fd\u6578\u4f86\u6c42\u51fa List \u4e2d\u6578\u64da\u7684\u6807\u51c6\u5dee (standard deviation)\uff0c\u7d50\u679c\u70ba 1.4142135623730951\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5b78\u7fd2\u4e86\u5982\u4f55\u4f7f\u7528 React.JS \u7684 List \u7d44\u4ef6\u548c calculateStandardDeviation \u51fd\u6578\u4f86\u6c42\u51fa List \u4e2d\u6578\u64da\u7684\u6807\u51c6\u5dee (standard deviation)\u3002\u4f7f\u7528 React.JS \u4f86\u6c42 List \u7684\u6807\u51c6\u5dee (standard deviation) \u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u5b9a\u7fa9\u4e00\u500b List \u7d44\u4ef6\uff0c\u4e26\u5c07 List \u4e2d\u7684\u6578\u64da\u50b3\u5165 List \u7d44\u4ef6\u4e2d\uff0c\u7136\u5f8c\u4f7f\u7528 calculateStandardDeviation \u51fd\u6578\u4f86\u6c42\u51fa List \u4e2d\u6578\u64da\u7684\u6807\u51c6\u5dee (standard deviation) \u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528React.JS\u6c42\u53d6\u6a19\u6e96\u5dee\uff0c\u4e26\u63d0\u4f9b\u7c21\u55ae\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff0c\u8b93\u8b80\u8005\u53ef\u4ee5\u8f15\u9b06\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528React.JS\u6c42\u53d6\u6a19\u6e96\u5dee\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":[184,183],"tags":[182,181],"class_list":["post-6504","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1GU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6504","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=6504"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6504\/revisions"}],"predecessor-version":[{"id":6505,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6504\/revisions\/6505"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}