{"id":9,"date":"2019-10-15T20:34:46","date_gmt":"2019-10-15T12:34:46","guid":{"rendered":"http:\/\/yichenghui.net\/?p=9"},"modified":"2022-09-13T14:13:38","modified_gmt":"2022-09-13T06:13:38","slug":"simplealgorithm","status":"publish","type":"post","link":"https:\/\/yichenghui.net\/index.php\/2019\/10\/15\/simplealgorithm\/","title":{"rendered":"\u7b80\u5355\u7b97\u6cd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u83f2\u6ce2\u90a3\u5207\u6570\u5217<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function feibo(n){<br>    return n&lt;=2?1:feibo(n-1)+feibo(n-2)<br>} <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6c34\u4ed9\u82b1\u6570<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function number(n){\n    if(n&lt;100){\n        return \n    }\n    let result=[]\n    for(let i=0;i&lt;=n;i++){\n        let tempArr=i.toString().split('');\n        let count=tempArr\n                 .map(item=&gt;Math.pow(item,tempArr.length))\n                 .reduce((v1,v2)=&gt;v1+v2);\n        if(count==i){\n            result.push(i)\n        }\n    }\n    return result\n}<\/pre>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>\u7b80\u5355BusEvent(\u53d1\u5e03\u8ba2\u9605\u6a21\u5f0f)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Bus {\n    event = {}\n    $on(name, callback) {\n        this.event[name] = callback\n    }\n    $emit(name, data) {\n        if (this.event[name]) {\n            this.event[name](data)\n        }\n    }\n}\n\nlet&nbsp;bus&nbsp;=&nbsp;new&nbsp;Bus()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\nbus.$on('test',&nbsp;res&nbsp;=&gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;console.log(res);\n})\n\nsetTimeout(()&nbsp;=&gt;&nbsp;{\n&nbsp;&nbsp;&nbsp; bus.$emit('test',&nbsp;[1,&nbsp;2,&nbsp;3])\n},&nbsp;1000); <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u83f2\u6ce2\u90a3\u5207\u6570\u5217 function feibo(n){ return n&lt;=2?1:feibo(n-1)+f &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/yichenghui.net\/index.php\/2019\/10\/15\/simplealgorithm\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u7b80\u5355\u7b97\u6cd5\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"_kadence_starter_templates_imported_post":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-aside","hentry","category-javascript","post_format-post-format-aside"],"_links":{"self":[{"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":4,"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":15,"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions\/15"}],"wp:attachment":[{"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yichenghui.net\/index.php\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}