From 3722bccea8605dfef55dd270e7f2ca14a1c03ae7 Mon Sep 17 00:00:00 2001 From: Rain120 Date: Sun, 5 Jul 2020 17:21:23 +0800 Subject: [PATCH 1/9] feat: plop new docs or template set alias; update docs about alias --- CHANGELOG.md | 9 ++-- README.md | 16 +++++- docs/.vuepress/config.js | 18 +++---- docs/.vuepress/utils/alias.js | 78 --------------------------- docs/.vuepress/utils/alias.json | 55 +++++++++++++++++++ docs/.vuepress/utils/sidebarHelper.js | 39 +++++++++++++- docs/zh/how-to-write-docs/README.md | 54 ++++++++++++++++++- package.json | 2 +- plopfile.js | 47 +++++++++++++++- zh-CN.md | 36 ++++++++++++- 10 files changed, 250 insertions(+), 104 deletions(-) delete mode 100644 docs/.vuepress/utils/alias.js create mode 100644 docs/.vuepress/utils/alias.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e2301..9982c5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.0.0 (2020-04-13) +# 1.0.0 (2020-07-05) ### Bug Fixes @@ -50,6 +50,7 @@ * observer pattern ([77c78f7](https://github.com/Rain120/awesome-javascript-code-implementation/commit/77c78f7359161c0e64b3143e3a66fea3f5d4eb46)) * plop create code and docs model ([2dece76](https://github.com/Rain120/awesome-javascript-code-implementation/commit/2dece76fbfd83514551dbabadf7c54d73674730d)) * plop new code and docs template ([61a936b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/61a936b58bc52a1cf984dc6156746b43f65da7f1)) +* plop new docs or template set alias; update docs about alias ([99acb07](https://github.com/Rain120/awesome-javascript-code-implementation/commit/99acb07f03348613efab69049a240bf04928dc6b)) * promise; debugger launch ([cc8ad80](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cc8ad803956e65431cedd97f1ebb333ffe78c28e)) * proxy design ([e615f39](https://github.com/Rain120/awesome-javascript-code-implementation/commit/e615f39497043f4c2357c7366cb13226b57208e6)) * sort -> bubbleSort(algorithm, readme, test) ([36fab7b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/36fab7b029d425ac129b6c4f202b18a9a3852fef)) @@ -60,10 +61,10 @@ * update readme for plans ([b427b96](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b427b9667cc97c77df75ef0af56eb84b6b4c3ba6)) * update test.yml -> ci.yml and set command ([43b96b6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/43b96b63fc2788a5ea37fa7567c6a6dced4b875f)) * update vdom-diff docs ([06590c5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/06590c56d0df7cbba68bb705cb7e159f6f765c3a)) -* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380)) -* update xmind ([4256758](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4256758c5fe0a036ce3ececc43f848e48964d7a0)) -* update xmind ([408ca68](https://github.com/Rain120/awesome-javascript-code-implementation/commit/408ca685142dc425e90be64a284016d57d580893)) * update xmind ([cb23933](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cb23933f46152c59a7b08f84d7355b35bba25002)) +* update xmind ([408ca68](https://github.com/Rain120/awesome-javascript-code-implementation/commit/408ca685142dc425e90be64a284016d57d580893)) +* update xmind ([4256758](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4256758c5fe0a036ce3ececc43f848e48964d7a0)) +* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380)) * update: plans; fix: readme bug ([d44e559](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d44e559def7834fcccbb19797a1d29bf5cc4e5b7)) * vdom diff algorithm ([3b7779d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3b7779dcad7e184027d1bddfa6387224c2f009d3)) * vuepress docs v1.0.0 ([785caeb](https://github.com/Rain120/awesome-javascript-code-implementation/commit/785caeb41beeff7a0f53646fc952d1c89ebb61d5)) diff --git a/README.md b/README.md index ae6ceda..5e415c5 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,9 @@ Document Link: [Xmind Download](plans.xmind) -#### 🔨 Usage +#### 🔨 Quick Start -⌨️ + 生成 `code` 模板 @@ -69,6 +69,18 @@ npm run template-docs [how-to-write-docs](docs/zh/how-to-write-docs/README.md) +#### 🌏Deploy + +##### -> https://rain120.github.io/awesome-javascript-code-implementation + +``` +npm run deploy +``` + +##### -> https://awesome-javascript-code-implementation.netlify.com/ + +`netlify auto deploy` + #### 🤝 Contributing ![PR](https://img.shields.io/badge/PRs-Welcome-orange?style=flat-square&logo=appveyor) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 4c0a114..b834173 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -1,23 +1,17 @@ const path = require('path'); const plugins = require('./utils/plugins'); -const { sidebarHelper } = require('./utils/sidebarHelper'); +const { sidebarHelper, sortSidebar } = require('./utils/sidebarHelper'); const nav = require('./utils/nav'); /** - * @description [guide, how-to-write-docs, ...] + * sortSidebar 根据 alias 设置顺序,默认顺序为 文件夹名字的顺序 */ -const docs = sidebarHelper(); -const sidebar = []; -docs.map(item => { - if (item.path.includes('guide') || item.path.includes('how-to-write-docs')) { - sidebar.unshift(item) - } else { - sidebar.push(item) - } -}); -[sidebar[1], sidebar[0]] = [sidebar[0], sidebar[1]]; + +const sidebar = sortSidebar(sidebarHelper()); // git pages base project name -> /awesome-javascript-code-implementation/, netlify base: '' +// deploy https://rain120.github.io/awesome-javascript-code-implementation build has argv +// more info go to deploy.sh const ARGV = (process.argv || []).slice(-1)[0]; const base = ARGV !== 'docs' ? ARGV : ''; diff --git a/docs/.vuepress/utils/alias.js b/docs/.vuepress/utils/alias.js deleted file mode 100644 index e8ec427..0000000 --- a/docs/.vuepress/utils/alias.js +++ /dev/null @@ -1,78 +0,0 @@ -/* - * @Author: Rainy - * @Date: 2020-01-31 11:42:43 - * @LastEditors: Rainy - * @LastEditTime: 2020-03-19 17:25:45 - */ - -const alias = { - 'guide': '介绍', - 'how-to-write-docs': '如何写文档? ', - - // math - 'math': '数学', - 'factorial': '阶乘', - 'fibonacci': '斐波那契数列', - 'gcd': '最大公约数', - 'lcm': '最小公倍数', - 'binary': '二进制', - - // primitive - 'primitive': '原生 Javascript', - - // function - 'function': '函数', - 'debounce': '防抖', - 'throttle': '节流', - - // vdom-diff - 'vdom-diff': '实现React/Vue DOM Diff算法', - - // es6 - 'es6': 'ECMAScript 6(ES6)', - 'promise': '手写Promise', - - // Array - 'array': 'Array(MDN + Function)', - - // Object - 'object': 'Object(MDN + Function)', - - // types - 'types': 'Types', - - // utils - 'utils': 'Utils', - - // design-pattern - 'design-pattern': '设计模式', - 'adapter-pattern': '适配器模式', - 'decorator-pattern': '装饰器模式', - 'factory-pattern': '工厂模式', - 'facade-pattern': '外观模式', - 'iterator-pattern': '迭代器模式', - 'proxy-pattern': '代理模式', - 'observer-pattern': '观察者模式', - 'singleton-pattern': '单例模式', - - // algorithms - 'algorithms': '算法', - 'binaryTree': '二叉树', - - // sort - 'sort': '排序算法', - 'bubbleSort': '冒泡排序', - 'bucketSort': '桶排序', - 'countingSort': '计数排序', - 'heapSort': '堆排序', - 'insertionSort': '插入排序', - 'mergeSort': '归并排序', - 'quickSort': '快速排序', - 'radixSort': '基数排序', - 'selectionSort': '选择排序', - 'shellSort': '希尔排序', -}; - -module.exports = { - alias, -} diff --git a/docs/.vuepress/utils/alias.json b/docs/.vuepress/utils/alias.json new file mode 100644 index 0000000..ce34873 --- /dev/null +++ b/docs/.vuepress/utils/alias.json @@ -0,0 +1,55 @@ +{ + "guide": "介绍", + "how-to-write-docs": "如何写文档? ", + "math-------": "", + "math": "数学", + "factorial": "阶乘", + "fibonacci": "斐波那契数列", + "gcd": "最大公约数", + "lcm": "最小公倍数", + "binary": "二进制", + "primitive-------": "", + "primitive": "原生 Javascript", + "function-------": "", + "function": "函数", + "debounce": "防抖", + "throttle": "节流", + "vdom-diff-------": "", + "vdom-diff": "实现React/Vue DOM Diff算法", + "es6-------": "", + "es6": "ECMAScript 6(ES6)", + "promise": "手写Promise", + "Array-------": "", + "array": "Array(MDN + Function)", + "Object-------": "", + "object": "Object(MDN + Function)", + "types-------": "", + "types": "Types", + "utils-------": "", + "utils": "Utils", + "design-pattern-------": "", + "design-pattern": "设计模式", + "adapter-pattern": "适配器模式", + "decorator-pattern": "装饰器模式", + "factory-pattern": "工厂模式", + "facade-pattern": "外观模式", + "iterator-pattern": "迭代器模式", + "proxy-pattern": "代理模式", + "observer-pattern": "观察者模式", + "singleton-pattern": "单例模式", + "algorithms-------": "", + "algorithms": "算法", + "binaryTree": "二叉树", + "sort-------": "", + "sort": "排序算法", + "bubbleSort": "冒泡排序", + "bucketSort": "桶排序", + "countingSort": "计数排序", + "heapSort": "堆排序", + "insertionSort": "插入排序", + "mergeSort": "归并排序", + "quickSort": "快速排序", + "radixSort": "基数排序", + "selectionSort": "选择排序", + "shellSort": "希尔排序" +} \ No newline at end of file diff --git a/docs/.vuepress/utils/sidebarHelper.js b/docs/.vuepress/utils/sidebarHelper.js index 03c7795..7acaf7f 100644 --- a/docs/.vuepress/utils/sidebarHelper.js +++ b/docs/.vuepress/utils/sidebarHelper.js @@ -4,7 +4,22 @@ const path = require('path'); const filePath = path.join(__dirname, '../../zh'); const ignore = ['images', '.vuepress', '.DS_Store']; const README_REG = /README/; -const { alias } = require('./alias'); + +/** + * @description 特殊处理文档顺序 + * alias 的顺序决定了文档菜单的目录顺序,子菜单亦可 + * Eg: + * p2: p2 + * p1: p1 + * p1-c2: p1-c2 + * p1-c1: p1-c1 + * -> 菜单顺序是 + * p2 + * p1 + * c2 + * c1 + */ +const alias = require('./alias.json'); const mapper = code => { return alias[code]; @@ -32,6 +47,7 @@ function helper({ dir, fPath }) { const name = sub.replace('\.md', ''); return { title: mapper(name) || `${name}`, + key: name, path: `${prefixPath}/${fPath}/${name}`, } } @@ -39,6 +55,7 @@ function helper({ dir, fPath }) { return { title: mapper(fPath) || `${fPath}`, + key: fPath, path: `${prefixPath}/${fPath}/`, collapsable: true, children: Array.isArray(children) ? children : [children], @@ -53,6 +70,24 @@ function sidebarHelper(dir = filePath) { }); } + +function findIndex(value) { + return Object.keys(alias).findIndex(item => item === value) +} + +function sortSidebar(sidebar) { + sidebar.sort((a, b) => { + return findIndex(a.key) - findIndex(b.key); + }); + for (const item of sidebar) { + if (item && Array.isArray(item.children)) { + item.children = sortSidebar(item.children); + } + } + return sidebar; +} + module.exports = { - sidebarHelper + sidebarHelper, + sortSidebar, }; diff --git a/docs/zh/how-to-write-docs/README.md b/docs/zh/how-to-write-docs/README.md index 44d45ab..78529d6 100644 --- a/docs/zh/how-to-write-docs/README.md +++ b/docs/zh/how-to-write-docs/README.md @@ -20,6 +20,13 @@ npm run docs touch docs/zh/test/README.md ``` +```sh +# npm run docs +? please input the docs model name: model +? please input the docs model alias name (default same as model name)? +? generator model path (etc: docs/zh/model) ? docs/zh +``` + `Eg: File Path` ```sh @@ -46,11 +53,54 @@ docs/zh │   │   └── README.md ``` +**模板文件** +`plop-templates/docs/zh/README.md.hbs` + +<<< @/plop-templates/docs/zh/README.md.hbs + +## 新建 Code 模板 + 单测模板 + +```sh +npm run template-docs +``` + +```sh +? please input the name: template +? please input the docs model alias name (default same as model name)? +? Do you want test file ? Yes +? generator path (etc: src/template) ? src +? generator model path (etc: docs/zh/model) ? docs/zh +``` + +**模板文件** + +`plop-templates/code/__tests__.ts.hbs` + +<<< @/plop-templates/code/__tests__.ts.hbs + +`plop-templates/code/index.ts.hbs` + +<<< @/plop-templates/code/index.ts.hbs + +`plop-templates/code/README.md.hbs` + +<<< @/plop-templates/code/README.md.hbs + +## 文档顺序 + +::: tip +`alias.json` 的顺序就是文档的顺序 +::: + ## 配置别名 -我们不支持中文名文件夹, 所以你需要给文件名配置别名, 只需要在`docs/.vuepress/utils/alias.js`中配置 `key-value`值即可 +::: tip +通过使用 [新建文件](#新建文件) 的脚本来动态配置 `alias`, 妈妈再也不用担心我找不到配置了。 +::: + +我们不支持中文名文件夹, 所以你需要给文件名配置别名, 只需要在`docs/.vuepress/utils/alias.json`中配置 `key-value`值即可 -<<< @/docs/.vuepress/utils/alias.js +<<< @/docs/.vuepress/utils/alias.json ## 图片 diff --git a/package.json b/package.json index e4bf4a5..9a180e7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "husky": { "hooks": { - "pre-commit": "lint-staged", + "pre-commit": "npm run changelog && npm run deploy && lint-staged", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, diff --git a/plopfile.js b/plopfile.js index 81bf00d..2d81a28 100644 --- a/plopfile.js +++ b/plopfile.js @@ -2,9 +2,42 @@ * @Author: Rainy * @Date: 2020-03-01 19:29:27 * @LastEditors: Rainy - * @LastEditTime: 2020-03-03 10:25:16 + * @LastEditTime: 2020-07-05 17:18:48 */ + +const path = require('path'); +const fs = require('fs'); + +const aliasPath = path.resolve('docs/.vuepress/utils/alias.json') + +/** + * + * @param {string} key modal name + * @param {string} value modal alias + */ +function addAlias(key, value, needSplitLine = false) { + key = key.trim().split(' ')[0]; + const data = fs.readFileSync(aliasPath, 'utf-8'); + const content = JSON.parse(data); + if (!value) { + value = key; + } + // if (needSplitLine) { + // const split = `${key}-------`; + // content[split] = ''; + // } + if (!content[key]) { + content[key] = value; + } else { + throw new Error('The key is exist'); + } + + const file = JSON.stringify(content, null, 2); + + fs.writeFileSync(aliasPath, new Buffer(file)) +} + module.exports = plop => { plop.setGenerator('template', { description: 'Create root template', @@ -59,6 +92,11 @@ module.exports = plop => { message: 'please input the docs model name: ', default: 'model' }, + { + type: 'input', + name: 'alias', + message: 'please input the docs model alias name (default same as model name)?' + }, { type: 'input', name: 'path', @@ -67,6 +105,7 @@ module.exports = plop => { } ], actions: answer => { + addAlias(answer.name, answer.alias); return [ { type: 'add', @@ -85,6 +124,11 @@ module.exports = plop => { message: 'please input the name: ', default: 'template' }, + { + type: 'input', + name: 'alias', + message: 'please input the docs model alias name (default same as model name)?' + }, { type: 'confirm', name: 'needTest', @@ -104,6 +148,7 @@ module.exports = plop => { } ], actions: answer => { + addAlias(answer.name, answer.alias, true); let actions = [ { type: 'add', diff --git a/zh-CN.md b/zh-CN.md index cfc9337..89f4547 100644 --- a/zh-CN.md +++ b/zh-CN.md @@ -47,9 +47,41 @@ [Xmind 下载地址](plans.xmind) -#### 🔨 使用 +#### 🔨 快速开发 -⌨️ 正在拼命开发中... + + +生成 `code` 模板 + +```sh +npm run template +``` + +生成 `docs` 模板 + +```sh +npm run docs +``` + +同时生成 `code` `docs`模板 + +``` +npm run template-docs +``` + +[how-to-write-docs](docs/zh/how-to-write-docs/README.md) + +#### 发布 + +##### -> https://rain120.github.io/awesome-javascript-code-implementation + +``` +npm run deploy +``` + +##### -> https://awesome-javascript-code-implementation.netlify.com/ + +`netlify` 自动发布 #### 🤝 贡献 ![PR](https://img.shields.io/badge/PRs-Welcome-orange?style=flat-square&logo=appveyor) From cf084d80099aa5445bd6522a6d8be373ad2c73fb Mon Sep 17 00:00:00 2001 From: Rain120 Date: Sun, 26 Jul 2020 11:07:05 +0800 Subject: [PATCH 2/9] feat: sword means offer: 03 find repeat number; fix: plop template; readme title --- docs/.vuepress/utils/alias.json | 5 ++- docs/zh/algorithms/binaryTree/README.md | 2 +- docs/zh/array/arrayMove/README.md | 2 +- docs/zh/array/find/README.md | 2 +- docs/zh/array/isArray/README.md | 2 +- .../singleton-pattern/README.md | 2 +- docs/zh/es6/promise/README.md | 2 +- docs/zh/function/debounce/README.md | 2 +- docs/zh/function/throttle/README.md | 2 +- docs/zh/object/is/README.md | 2 +- docs/zh/primitive/apply/README.md | 2 +- docs/zh/primitive/bind/README.md | 2 +- docs/zh/primitive/call/README.md | 2 +- docs/zh/primitive/instanceof/README.md | 2 +- docs/zh/primitive/new/README.md | 2 +- docs/zh/sort/bubbleSort/README.md | 2 +- docs/zh/sort/bucketSort/README.md | 2 +- docs/zh/sort/countingSort/README.md | 2 +- docs/zh/sort/heapSort/README.md | 2 +- docs/zh/sort/insertionSort/README.md | 2 +- docs/zh/sort/mergeSort/README.md | 2 +- docs/zh/sort/quickSort/README.md | 2 +- docs/zh/sort/radixSort/README.md | 2 +- docs/zh/sort/selectionSort/README.md | 2 +- docs/zh/sort/shellSort/README.md | 2 +- .../03-find-repeat-number/README.md | 33 +++++++++++++++++ docs/zh/sword-means-offer/README.md | 9 +++++ docs/zh/vdom-diff/README.md | 2 +- plop-templates/code/README.md.hbs | 2 +- plop-templates/code/__tests__.ts.hbs | 4 +-- plop-templates/docs/zh/README.md.hbs | 2 +- src/Array/arrayMove/README.md | 2 +- src/Array/find/README.md | 2 +- src/Array/isArray/README.md | 2 +- src/Object/is/README.md | 2 +- src/algorithms/sort/bubbleSort/README.md | 2 +- src/algorithms/sort/bucketSort/README.md | 2 +- src/algorithms/sort/countingSort/README.md | 2 +- src/algorithms/sort/heapSort/README.md | 2 +- src/algorithms/sort/insertionSort/README.md | 2 +- src/algorithms/sort/mergeSort/README.md | 2 +- src/algorithms/sort/quickSort/README.md | 2 +- src/algorithms/sort/radixSort/README.md | 2 +- src/algorithms/sort/selectionSort/README.md | 2 +- src/algorithms/sort/shellSort/README.md | 2 +- .../singleton-pattern/README.md | 2 +- src/function/debounce/README.md | 2 +- src/function/throttle/README.md | 2 +- src/primitive/apply/README.md | 2 +- src/primitive/bind/README.md | 2 +- src/primitive/call/README.md | 2 +- src/primitive/instanceof/README.md | 2 +- src/primitive/new/README.md | 2 +- src/promise/README.md | 2 +- .../03-find-repeat-number/README.md | 30 ++++++++++++++++ .../03-find-repeat-number/__tests__.ts | 24 +++++++++++++ .../03-find-repeat-number/index.ts | 36 +++++++++++++++++++ 57 files changed, 188 insertions(+), 53 deletions(-) create mode 100644 docs/zh/sword-means-offer/03-find-repeat-number/README.md create mode 100644 docs/zh/sword-means-offer/README.md create mode 100644 src/sword-means-offer/03-find-repeat-number/README.md create mode 100644 src/sword-means-offer/03-find-repeat-number/__tests__.ts create mode 100644 src/sword-means-offer/03-find-repeat-number/index.ts diff --git a/docs/.vuepress/utils/alias.json b/docs/.vuepress/utils/alias.json index ce34873..ae6752b 100644 --- a/docs/.vuepress/utils/alias.json +++ b/docs/.vuepress/utils/alias.json @@ -51,5 +51,8 @@ "quickSort": "快速排序", "radixSort": "基数排序", "selectionSort": "选择排序", - "shellSort": "希尔排序" + "shellSort": "希尔排序", + "sword-means-offer-------": "", + "sword-means-offer": "剑指 Offer", + "03-find-repeat-number": "03. 数组中重复的数字" } \ No newline at end of file diff --git a/docs/zh/algorithms/binaryTree/README.md b/docs/zh/algorithms/binaryTree/README.md index cdd6d24..516a92b 100644 --- a/docs/zh/algorithms/binaryTree/README.md +++ b/docs/zh/algorithms/binaryTree/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 在计算机科学中, 二叉树是每个节点最多只有两个分支的树结构。通常分支被称作 "左子树" 或 "右子树"。二叉树的分支具有左右次序, 不能随意颠倒。 diff --git a/docs/zh/array/arrayMove/README.md b/docs/zh/array/arrayMove/README.md index 22fd44f..1e0bf65 100644 --- a/docs/zh/array/arrayMove/README.md +++ b/docs/zh/array/arrayMove/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 通过 `splice`方法去复制需要移动的数组元素,并拼接新数组。 diff --git a/docs/zh/array/find/README.md b/docs/zh/array/find/README.md index 2d541f5..851697e 100644 --- a/docs/zh/array/find/README.md +++ b/docs/zh/array/find/README.md @@ -10,7 +10,7 @@ Array.prototype.find = function(predicate, /* thisArg*/) {} function (collection, predicate) {} ``` -## 原理 +## 解题思路 or 实现原理 `find` 方法对数组中的每一项元素执行一次 `predicate` 函数, 直至有一个 `predicate` 返回 `true`. 当找到了这样一个元素后, 该方法会立即返回这个元素的值, 否则返回 `undefined`. 注意`predicate` 函数会为数组中的每个索引调用即从 0 到 `length - 1`, 而不仅仅是那些被赋值的索引, 这意味着对于稀疏数组来说, 该方法的效率要低于那些只遍历有值的索引的方法. diff --git a/docs/zh/array/isArray/README.md b/docs/zh/array/isArray/README.md index 4d5d6cb..cec5381 100644 --- a/docs/zh/array/isArray/README.md +++ b/docs/zh/array/isArray/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 使用 `Object.prototype.toString` 取得对象的一个内部属性 `[[Class]]`,然后依据这个属性,返回 `'[object Array]'` 字符串作为结果(`ECMA`标准中使用`[[]]`来表示语言内部用到的、外部不可直接访问的属性,称为`内部属性`)。利用这 个方法,再配合 `call`,我们可以取得任何对象的内部属性 `[[Class]]`,然后把类型检测转化为字符串比较,以达到我们的目的。 diff --git a/docs/zh/design-pattern/singleton-pattern/README.md b/docs/zh/design-pattern/singleton-pattern/README.md index 2627d9e..0a2bd31 100644 --- a/docs/zh/design-pattern/singleton-pattern/README.md +++ b/docs/zh/design-pattern/singleton-pattern/README.md @@ -10,7 +10,7 @@ - 单例类必须给所有其他对象提供这一实例。 -## 原理 +## 解题思路 or 实现原理 一个类能返回对象一个引用(永远是同一个)和一个获得该实例的方法(必须是静态方法, 通常使用 `getInstance` 这个名称); 当我们调用这个方法时, 如果类持有的引用不为空就返回这个引用, 如果类保持的引用为空就创建该类的实例并将实例的引用赋予该类保持的引用; 同时我们还将该类的构造函数定义为私有方法, 这样其他处的代码就无法通过调用该类的构造函数来实例化该类的对象, 只有通过该类提供的静态方法来得到该类的唯一实例。 diff --git a/docs/zh/es6/promise/README.md b/docs/zh/es6/promise/README.md index 984dcec..9257eb1 100644 --- a/docs/zh/es6/promise/README.md +++ b/docs/zh/es6/promise/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 `Promise` 对象是一个代理对象(代理一个值),被代理的值在`Promise`对象创建时可能是未知的。它允许你为异步操作的成功和失败分别绑定相应的处理方法`(handlers)`。 这让异步方法可以像同步方法那样返回值,但并不是立即返回最终执行结果,而是一个能代表未来出现的结果的`promise`对象。 diff --git a/docs/zh/function/debounce/README.md b/docs/zh/function/debounce/README.md index b56a499..36a9e09 100644 --- a/docs/zh/function/debounce/README.md +++ b/docs/zh/function/debounce/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 - Lodash diff --git a/docs/zh/function/throttle/README.md b/docs/zh/function/throttle/README.md index 51e1770..a8267dd 100644 --- a/docs/zh/function/throttle/README.md +++ b/docs/zh/function/throttle/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 - Lodash diff --git a/docs/zh/object/is/README.md b/docs/zh/object/is/README.md index 7eb80bc..b96ed3f 100644 --- a/docs/zh/object/is/README.md +++ b/docs/zh/object/is/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 Object.is() 判断两个值是否相同. 如果下列任何一项成立, 则两个值相同: diff --git a/docs/zh/primitive/apply/README.md b/docs/zh/primitive/apply/README.md index 4926b96..ed623b6 100644 --- a/docs/zh/primitive/apply/README.md +++ b/docs/zh/primitive/apply/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 调用一个具有给定 `this` 值的函数,以及作为一个数组(或类似数组对象)提供的参数。 diff --git a/docs/zh/primitive/bind/README.md b/docs/zh/primitive/bind/README.md index 92abccc..432522b 100644 --- a/docs/zh/primitive/bind/README.md +++ b/docs/zh/primitive/bind/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 创建一个新的函数, 在 `bind()` 被调用时, 这个新函数的 `this` 被指定为 `bind()` 的第一个参数, 而其余参数将作为新函数的参数, 供调用时使用。 diff --git a/docs/zh/primitive/call/README.md b/docs/zh/primitive/call/README.md index 31ebed5..45fe090 100644 --- a/docs/zh/primitive/call/README.md +++ b/docs/zh/primitive/call/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 使用一个指定的 `this` 值和单独给出的一个或多个参数来调用一个函数。 diff --git a/docs/zh/primitive/instanceof/README.md b/docs/zh/primitive/instanceof/README.md index f861016..3c8c698 100644 --- a/docs/zh/primitive/instanceof/README.md +++ b/docs/zh/primitive/instanceof/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 判断实例对象的`__proto__`和构造函数的`prototype`是不是引用同一个地址 diff --git a/docs/zh/primitive/new/README.md b/docs/zh/primitive/new/README.md index a443c2c..d4a2c87 100644 --- a/docs/zh/primitive/new/README.md +++ b/docs/zh/primitive/new/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 `new`关键字做了哪些事? diff --git a/docs/zh/sort/bubbleSort/README.md b/docs/zh/sort/bubbleSort/README.md index f17df1b..6c468ce 100644 --- a/docs/zh/sort/bubbleSort/README.md +++ b/docs/zh/sort/bubbleSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 冒泡排序(`Bubble Sort`)也是一种简单直观的排序算法。它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成。这个算法的名字由来是因为越小的元素会经由交换慢慢“浮”到数列的顶端。 diff --git a/docs/zh/sort/bucketSort/README.md b/docs/zh/sort/bucketSort/README.md index f5c8888..3127d62 100644 --- a/docs/zh/sort/bucketSort/README.md +++ b/docs/zh/sort/bucketSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 桶排序是计数排序的升级版。它利用了函数的映射关系, 高效与否的关键就在于这个映射函数的确定。为了使桶排序更加高效, 我们需要做到这两点: diff --git a/docs/zh/sort/countingSort/README.md b/docs/zh/sort/countingSort/README.md index 996b14d..88e3bb6 100644 --- a/docs/zh/sort/countingSort/README.md +++ b/docs/zh/sort/countingSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 计数排序的核心在于将输入的数据值转化为键存储在额外开辟的数组空间中。作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范围的整数。 diff --git a/docs/zh/sort/heapSort/README.md b/docs/zh/sort/heapSort/README.md index 9d57c44..3bc0719 100644 --- a/docs/zh/sort/heapSort/README.md +++ b/docs/zh/sort/heapSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 堆排序(`Heap sort`)是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构, 并同时满足堆积的性质: 即子结点的键值或索引总是小于(或者大于)它的父节点。堆排序可以说是一种利用堆的概念来排序的选择排序。分为两种方法: diff --git a/docs/zh/sort/insertionSort/README.md b/docs/zh/sort/insertionSort/README.md index 30359dd..b705d4a 100644 --- a/docs/zh/sort/insertionSort/README.md +++ b/docs/zh/sort/insertionSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法。它的工作原理是通过构建有序序列, 对于未排序数据, 在已排序序列中从后向前扫描, 找到相应位置并插入。 diff --git a/docs/zh/sort/mergeSort/README.md b/docs/zh/sort/mergeSort/README.md index ddc0da5..350547d 100644 --- a/docs/zh/sort/mergeSort/README.md +++ b/docs/zh/sort/mergeSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 归并排序(`Merge sort`)是建立在归并操作上的一种有效的排序算法。该算法是采用分治法(`Divide and Conquer`)的一个非常典型的应用。 diff --git a/docs/zh/sort/quickSort/README.md b/docs/zh/sort/quickSort/README.md index 9885e82..d8dee0c 100644 --- a/docs/zh/sort/quickSort/README.md +++ b/docs/zh/sort/quickSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下, 排序 `n`个项目要 `Ο(nlogn)` 次比较。在最坏状况下则需要 `Ο(n2)` 次比较, 但这种状况并不常见。事实上, 快速排序通常明显比其他 `Ο(nlogn)` 算法更快, 因为它的内部循环(`inner loop`)可以在大部分的架构上很有效率地被实现出来。 diff --git a/docs/zh/sort/radixSort/README.md b/docs/zh/sort/radixSort/README.md index 2e4a573..70a8b25 100644 --- a/docs/zh/sort/radixSort/README.md +++ b/docs/zh/sort/radixSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 基数排序是一种非比较型整数排序算法, 其原理是将整数按位数切割成不同的数字, 然后按每个位数分别比较。由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数, 所以基数排序也不是只能使用于整数。 diff --git a/docs/zh/sort/selectionSort/README.md b/docs/zh/sort/selectionSort/README.md index df05c94..d45b035 100644 --- a/docs/zh/sort/selectionSort/README.md +++ b/docs/zh/sort/selectionSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 选择排序是一种简单直观的排序算法 `d`, 无论什么数据进去都是 `O(n²)` 的时间复杂度。所以用到它的时候`d`, 数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。 diff --git a/docs/zh/sort/shellSort/README.md b/docs/zh/sort/shellSort/README.md index f5caec6..88b97d1 100644 --- a/docs/zh/sort/shellSort/README.md +++ b/docs/zh/sort/shellSort/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 希尔排序, 也称递减增量排序算法, 是插入排序的一种更高效的改进版本。但希尔排序是非稳定排序算法。 diff --git a/docs/zh/sword-means-offer/03-find-repeat-number/README.md b/docs/zh/sword-means-offer/03-find-repeat-number/README.md new file mode 100644 index 0000000..887de03 --- /dev/null +++ b/docs/zh/sword-means-offer/03-find-repeat-number/README.md @@ -0,0 +1,33 @@ +## 题目 + +找出数组中重复的数字。 + +在一个长度为 `n` 的数组 `nums` 里的所有数字都在 **`0~n - 1`** 的范围内。数组中某些数字是重复的, 但不知道有几个数字重复了, 也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 + +示例 1: + +输入: + +``` +[2, 3, 1, 0, 2, 5, 3] +输出: 2 或 3 +``` +  + +限制: + +``` +2 <= n <= 100000 +``` + +来源: 力扣[LeetCode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof) + +## 解题思路 or 实现原理 + +1. 遍历该数组, 检查是否出现过, 首次出现过就标识, 再次出现就返回该值。 + +2. 由于题目限定了所有数字都在 **`0~n - 1`** 的范围内, 即元素位置 `index` 取到的值 **也会在当前数组的范围内**, 所以只需要遍历该数组, 如果遍历的值不等于当前的 `index`, 就把它放到对应的值位置上, 如果该位置上存在该值, 结果就是该值。 + +## 实现代码 + +<<< @/src/sword-means-offer/03-find-repeat-number/index.ts diff --git a/docs/zh/sword-means-offer/README.md b/docs/zh/sword-means-offer/README.md new file mode 100644 index 0000000..f54992d --- /dev/null +++ b/docs/zh/sword-means-offer/README.md @@ -0,0 +1,9 @@ +### 剑指 Offer + +::: tip +主要学习并实现 **剑指 Offer** 中的算法 +::: + +#### 目录 + +- [x] [剑指 Offer 03. 数组中重复的数字](./03-find-repeat-number/README.md) diff --git a/docs/zh/vdom-diff/README.md b/docs/zh/vdom-diff/README.md index 0f1b4bb..779dee2 100644 --- a/docs/zh/vdom-diff/README.md +++ b/docs/zh/vdom-diff/README.md @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 ### 常规 DOM 渲染 diff --git a/plop-templates/code/README.md.hbs b/plop-templates/code/README.md.hbs index f0046ab..553cc6a 100644 --- a/plop-templates/code/README.md.hbs +++ b/plop-templates/code/README.md.hbs @@ -1,3 +1,3 @@ -### 原理 +### 解题思路 or 实现原理 ### 参考 diff --git a/plop-templates/code/__tests__.ts.hbs b/plop-templates/code/__tests__.ts.hbs index dbc659c..f2af166 100644 --- a/plop-templates/code/__tests__.ts.hbs +++ b/plop-templates/code/__tests__.ts.hbs @@ -2,11 +2,11 @@ * @Author: Rainy * @Date: 2020-02-06 19:05:18 * @LastEditors: Rainy - * @LastEditTime: 2020-03-01 21:08:17 + * @LastEditTime: 2020-07-25 11:12:14 */ import { {{name}} } from '.'; -test('{{name}} instanceof {{name}} should false', () => { +test('Test {{name}}', () => { expect({{name}}()).toBe(undefined); }); diff --git a/plop-templates/docs/zh/README.md.hbs b/plop-templates/docs/zh/README.md.hbs index 13f251e..d7f5a76 100644 --- a/plop-templates/docs/zh/README.md.hbs +++ b/plop-templates/docs/zh/README.md.hbs @@ -1,4 +1,4 @@ -## 原理 +## 解题思路 or 实现原理 ## 实现代码 diff --git a/src/Array/arrayMove/README.md b/src/Array/arrayMove/README.md index a1ce397..f55ba76 100644 --- a/src/Array/arrayMove/README.md +++ b/src/Array/arrayMove/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 通过 `splice`方法去复制需要移动的数组元素,并拼接新数组。 diff --git a/src/Array/find/README.md b/src/Array/find/README.md index 8b5328f..ff19644 100644 --- a/src/Array/find/README.md +++ b/src/Array/find/README.md @@ -10,7 +10,7 @@ Array.prototype.find = function(predicate, /* thisArg*/) {} function (collection, predicate) {} ``` -### 原理 +### 解题思路 or 实现原理 `find` 方法对数组中的每一项元素执行一次 `predicate` 函数, 直至有一个 `predicate` 返回 `true`. 当找到了这样一个元素后, 该方法会立即返回这个元素的值, 否则返回 `undefined`. 注意`predicate` 函数会为数组中的每个索引调用即从 0 到 `length - 1`, 而不仅仅是那些被赋值的索引, 这意味着对于稀疏数组来说, 该方法的效率要低于那些只遍历有值的索引的方法. diff --git a/src/Array/isArray/README.md b/src/Array/isArray/README.md index 7d3fe6e..293667f 100644 --- a/src/Array/isArray/README.md +++ b/src/Array/isArray/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 使用 `Object.prototype.toString` 取得对象的一个内部属性 `[[Class]]`,然后依据这个属性,返回 `'[object Array]'` 字符串作为结果(`ECMA`标准中使用`[[]]`来表示语言内部用到的、外部不可直接访问的属性,称为`内部属性`)。利用这 个方法,再配合 `call`,我们可以取得任何对象的内部属性 `[[Class]]`,然后把类型检测转化为字符串比较,以达到我们的目的。 diff --git a/src/Object/is/README.md b/src/Object/is/README.md index d87817d..94a2ce4 100644 --- a/src/Object/is/README.md +++ b/src/Object/is/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 Object.is() 判断两个值是否相同. 如果下列任何一项成立, 则两个值相同: diff --git a/src/algorithms/sort/bubbleSort/README.md b/src/algorithms/sort/bubbleSort/README.md index 3c12511..4d40ce9 100644 --- a/src/algorithms/sort/bubbleSort/README.md +++ b/src/algorithms/sort/bubbleSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 冒泡排序(Bubble Sort)也是一种简单直观的排序算法。它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成。这个算法的名字由来是因为越小的元素会经由交换慢慢“浮”到数列的顶端。 diff --git a/src/algorithms/sort/bucketSort/README.md b/src/algorithms/sort/bucketSort/README.md index cf1bcc1..a8a9a9d 100644 --- a/src/algorithms/sort/bucketSort/README.md +++ b/src/algorithms/sort/bucketSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 桶排序是计数排序的升级版。它利用了函数的映射关系, 高效与否的关键就在于这个映射函数的确定。为了使桶排序更加高效, 我们需要做到这两点: diff --git a/src/algorithms/sort/countingSort/README.md b/src/algorithms/sort/countingSort/README.md index ed60a32..4c2298e 100644 --- a/src/algorithms/sort/countingSort/README.md +++ b/src/algorithms/sort/countingSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 计数排序的核心在于将输入的数据值转化为键存储在额外开辟的数组空间中。作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范围的整数。 diff --git a/src/algorithms/sort/heapSort/README.md b/src/algorithms/sort/heapSort/README.md index 0dfdf28..d77a1e3 100644 --- a/src/algorithms/sort/heapSort/README.md +++ b/src/algorithms/sort/heapSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 堆排序(`Heap sort`)是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构, 并同时满足堆积的性质: 即子结点的键值或索引总是小于(或者大于)它的父节点。堆排序可以说是一种利用堆的概念来排序的选择排序。分为两种方法: diff --git a/src/algorithms/sort/insertionSort/README.md b/src/algorithms/sort/insertionSort/README.md index b911b99..4b0472f 100644 --- a/src/algorithms/sort/insertionSort/README.md +++ b/src/algorithms/sort/insertionSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法。它的工作原理是通过构建有序序列, 对于未排序数据, 在已排序序列中从后向前扫描, 找到相应位置并插入。 diff --git a/src/algorithms/sort/mergeSort/README.md b/src/algorithms/sort/mergeSort/README.md index cb4a797..fa1de1f 100644 --- a/src/algorithms/sort/mergeSort/README.md +++ b/src/algorithms/sort/mergeSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 归并排序(`Merge sort`)是建立在归并操作上的一种有效的排序算法。该算法是采用分治法(`Divide and Conquer`)的一个非常典型的应用。 diff --git a/src/algorithms/sort/quickSort/README.md b/src/algorithms/sort/quickSort/README.md index 3a5cdc9..790b126 100644 --- a/src/algorithms/sort/quickSort/README.md +++ b/src/algorithms/sort/quickSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下, 排序 `n`个项目要 `Ο(nlogn)` 次比较。在最坏状况下则需要 `Ο(n2)` 次比较, 但这种状况并不常见。事实上, 快速排序通常明显比其他 `Ο(nlogn)` 算法更快, 因为它的内部循环(`inner loop`)可以在大部分的架构上很有效率地被实现出来。 diff --git a/src/algorithms/sort/radixSort/README.md b/src/algorithms/sort/radixSort/README.md index 495cd7b..f50d61f 100644 --- a/src/algorithms/sort/radixSort/README.md +++ b/src/algorithms/sort/radixSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 基数排序是一种非比较型整数排序算法, 其原理是将整数按位数切割成不同的数字, 然后按每个位数分别比较。由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数, 所以基数排序也不是只能使用于整数。 diff --git a/src/algorithms/sort/selectionSort/README.md b/src/algorithms/sort/selectionSort/README.md index d4198cf..31d289c 100644 --- a/src/algorithms/sort/selectionSort/README.md +++ b/src/algorithms/sort/selectionSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 选择排序是一种简单直观的排序算法 `d`, 无论什么数据进去都是 `O(n²)` 的时间复杂度。所以用到它的时候`d`, 数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。 diff --git a/src/algorithms/sort/shellSort/README.md b/src/algorithms/sort/shellSort/README.md index 7064893..29b9841 100644 --- a/src/algorithms/sort/shellSort/README.md +++ b/src/algorithms/sort/shellSort/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 希尔排序, 也称递减增量排序算法, 是插入排序的一种更高效的改进版本。但希尔排序是非稳定排序算法。 diff --git a/src/design-pattern/singleton-pattern/README.md b/src/design-pattern/singleton-pattern/README.md index d93848d..63d082e 100644 --- a/src/design-pattern/singleton-pattern/README.md +++ b/src/design-pattern/singleton-pattern/README.md @@ -10,7 +10,7 @@ - 单例类必须给所有其他对象提供这一实例。 -### 原理 +### 解题思路 or 实现原理 一个类能返回对象一个引用(永远是同一个)和一个获得该实例的方法(必须是静态方法, 通常使用 `getInstance` 这个名称); 当我们调用这个方法时, 如果类持有的引用不为空就返回这个引用, 如果类保持的引用为空就创建该类的实例并将实例的引用赋予该类保持的引用; 同时我们还将该类的构造函数定义为私有方法, 这样其他处的代码就无法通过调用该类的构造函数来实例化该类的对象, 只有通过该类提供的静态方法来得到该类的唯一实例。 diff --git a/src/function/debounce/README.md b/src/function/debounce/README.md index f253808..195780a 100644 --- a/src/function/debounce/README.md +++ b/src/function/debounce/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 #### 防抖 diff --git a/src/function/throttle/README.md b/src/function/throttle/README.md index f5820de..6343617 100644 --- a/src/function/throttle/README.md +++ b/src/function/throttle/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 #### 节流 diff --git a/src/primitive/apply/README.md b/src/primitive/apply/README.md index 1bdc088..8c157d6 100644 --- a/src/primitive/apply/README.md +++ b/src/primitive/apply/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 调用一个具有给定 `this` 值的函数,以及作为一个数组(或类似数组对象)提供的参数。 diff --git a/src/primitive/bind/README.md b/src/primitive/bind/README.md index 496f238..eda22e7 100644 --- a/src/primitive/bind/README.md +++ b/src/primitive/bind/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 创建一个新的函数, 在 `bind()` 被调用时, 这个新函数的 `this` 被指定为 `bind()` 的第一个参数, 而其余参数将作为新函数的参数, 供调用时使用。 diff --git a/src/primitive/call/README.md b/src/primitive/call/README.md index ea9704d..03259a8 100644 --- a/src/primitive/call/README.md +++ b/src/primitive/call/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 使用一个指定的 `this` 值和单独给出的一个或多个参数来调用一个函数。 diff --git a/src/primitive/instanceof/README.md b/src/primitive/instanceof/README.md index 34d0508..de6ea1a 100644 --- a/src/primitive/instanceof/README.md +++ b/src/primitive/instanceof/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 判断实例对象的`__proto__`和构造函数的`prototype`是不是引用同一个地址 diff --git a/src/primitive/new/README.md b/src/primitive/new/README.md index 7d4a72d..ac373eb 100644 --- a/src/primitive/new/README.md +++ b/src/primitive/new/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 `new`关键字做了哪些事? diff --git a/src/promise/README.md b/src/promise/README.md index 98a62d0..9a903f0 100644 --- a/src/promise/README.md +++ b/src/promise/README.md @@ -1,4 +1,4 @@ -### 原理 +### 解题思路 or 实现原理 `Promise` 对象是一个代理对象(代理一个值),被代理的值在`Promise`对象创建时可能是未知的。它允许你为异步操作的成功和失败分别绑定相应的处理方法`(handlers)`。 这让异步方法可以像同步方法那样返回值,但并不是立即返回最终执行结果,而是一个能代表未来出现的结果的`promise`对象。 diff --git a/src/sword-means-offer/03-find-repeat-number/README.md b/src/sword-means-offer/03-find-repeat-number/README.md new file mode 100644 index 0000000..26391c7 --- /dev/null +++ b/src/sword-means-offer/03-find-repeat-number/README.md @@ -0,0 +1,30 @@ +## 题目 + +找出数组中重复的数字。 + +在一个长度为 `n` 的数组 `nums` 里的所有数字都在 **`0~n - 1`** 的范围内。数组中某些数字是重复的, 但不知道有几个数字重复了, 也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 + +示例 1: + +输入: + +``` +[2, 3, 1, 0, 2, 5, 3] +输出: 2 或 3 +``` +  + +限制: + +``` +2 <= n <= 100000 +``` + +来源: 力扣[LeetCode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof) + +## 解题思路 or 实现原理 + +1. 遍历该数组, 检查是否出现过, 首次出现过就标识, 再次出现就返回该值。 + +2. 由于题目限定了所有数字都在 **`0~n - 1`** 的范围内, 即元素位置 `index` 取到的值 **也会在当前数组的范围内**, 所以只需要遍历该数组, 如果遍历的值不等于当前的 `index`, 就把它放到对应的值位置上, 如果该位置上存在该值, 结果就是该值。 + diff --git a/src/sword-means-offer/03-find-repeat-number/__tests__.ts b/src/sword-means-offer/03-find-repeat-number/__tests__.ts new file mode 100644 index 0000000..d36561e --- /dev/null +++ b/src/sword-means-offer/03-find-repeat-number/__tests__.ts @@ -0,0 +1,24 @@ +/* + * @Author: Rainy + * @Date: 2020-02-06 19:05:18 + * @LastEditors: Rainy + * @LastEditTime: 2020-07-26 10:54:08 + */ + +import { findRepeatNumber_1, findRepeatNumber_2 } from '.'; + +test('Test findRepeatNumber from [2, 3, 1, 0, 2, 5, 3] maybe 2 or 3', () => { + expect(findRepeatNumber_1([2, 3, 1, 0, 2, 5, 3])).toEqual(2 || 3); +}); + +test('Test findRepeatNumber from [2, 3, 1, 0, 2, 5, 3] maybe 2 or 3', () => { + expect(findRepeatNumber_1([1, 3, 2, 3])).toEqual(3); +}); + +test('Test findRepeatNumber from [2, 3, 1, 0, 2, 5, 3] maybe 2 or 3', () => { + expect(findRepeatNumber_2([2, 3, 1, 0, 2, 5, 3])).toEqual(2 || 3); +}); + +test('Test findRepeatNumber from [2, 3, 1, 0, 2, 5, 3] maybe 2 or 3', () => { + expect(findRepeatNumber_2([1, 3, 2, 3])).toEqual(3); +}); diff --git a/src/sword-means-offer/03-find-repeat-number/index.ts b/src/sword-means-offer/03-find-repeat-number/index.ts new file mode 100644 index 0000000..1573459 --- /dev/null +++ b/src/sword-means-offer/03-find-repeat-number/index.ts @@ -0,0 +1,36 @@ +/* + * @Author: Rainy + * @Date: 2019-11-14 19:25:01 + * @LastEditors: Rainy + * @LastEditTime: 2020-07-26 10:52:46 + */ + +import { ObjectMap } from "types"; + +/** + * @param {number[]} nums + * @return {number} + */ +export function findRepeatNumber_1(nums: number[]): number | undefined { + const map: ObjectMap = {}; + for (const num of nums) { + if (!map[num]) { + map[num] = true; + } else { + return num; + } + } +} + +export function findRepeatNumber_2(nums: number[]): number | undefined { + let num: number; + for (let index = 0; index < nums.length; index++) { + while ((num = nums[index]) !== index) { + if (num === nums[num]) { + return num; + } + + [nums[num], nums[index]] = [nums[index], nums[num]]; + } + } +} From c49bf2667ff411786de3bb2442a6a4b8af9a0083 Mon Sep 17 00:00:00 2001 From: Rain120 Date: Sun, 26 Jul 2020 11:24:38 +0800 Subject: [PATCH 3/9] fix: remove changelog at pre commit --- CHANGELOG.md | 8 +++++--- package.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9982c5c..551f5ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ -# 1.0.0 (2020-07-05) +# 1.0.0 (2020-07-26) ### Bug Fixes * algorithms docs build bug ([c4ed72d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/c4ed72d2da7b0f940a4f7530bdfaaa47631741ff)) +* changelog not add ([d69f43f](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d69f43f5112ea7d55242b46ca670ad54741bd940)) * ci bug ([f6185d6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/f6185d6f29e1587bba76f0772433441602bc8db7)) * deploy bug ([568b663](https://github.com/Rain120/awesome-javascript-code-implementation/commit/568b663a5fd6d1b4ab40043e0a693564d7dc3a84)) * gitalk cannot login; feat: manifest ([ee9e237](https://github.com/Rain120/awesome-javascript-code-implementation/commit/ee9e237314451244a13c6c4c13f8a119572b6ecb)) @@ -50,11 +51,12 @@ * observer pattern ([77c78f7](https://github.com/Rain120/awesome-javascript-code-implementation/commit/77c78f7359161c0e64b3143e3a66fea3f5d4eb46)) * plop create code and docs model ([2dece76](https://github.com/Rain120/awesome-javascript-code-implementation/commit/2dece76fbfd83514551dbabadf7c54d73674730d)) * plop new code and docs template ([61a936b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/61a936b58bc52a1cf984dc6156746b43f65da7f1)) -* plop new docs or template set alias; update docs about alias ([99acb07](https://github.com/Rain120/awesome-javascript-code-implementation/commit/99acb07f03348613efab69049a240bf04928dc6b)) +* plop new docs or template set alias; update docs about alias ([3722bcc](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3722bccea8605dfef55dd270e7f2ca14a1c03ae7)) * promise; debugger launch ([cc8ad80](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cc8ad803956e65431cedd97f1ebb333ffe78c28e)) * proxy design ([e615f39](https://github.com/Rain120/awesome-javascript-code-implementation/commit/e615f39497043f4c2357c7366cb13226b57208e6)) * sort -> bubbleSort(algorithm, readme, test) ([36fab7b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/36fab7b029d425ac129b6c4f202b18a9a3852fef)) * sort -> bucket, radix; algorithm -> binaryTree; add some types; docs: update readme; fix: tests format, ([b1d166c](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b1d166c7e56e37f35ab0bc7628186eeae15a4b60)) +* sword means offer: 03 find repeat number; fix: plop template; readme title ([cf084d8](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cf084d80099aa5445bd6522a6d8be373ad2c73fb)) * update docs -> algorithm: binary tree, sort ([5d57bc4](https://github.com/Rain120/awesome-javascript-code-implementation/commit/5d57bc4489551bffeca34102f2fce61b59996873)) * update docs -> design pattern function array object math primitive types utils ([1690af5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/1690af5ed96c46341465f72866732837e5c72200)) * update netlify status ([013b5ca](https://github.com/Rain120/awesome-javascript-code-implementation/commit/013b5ca5847873adabbff93a89daa41500ccf153)) @@ -62,9 +64,9 @@ * update test.yml -> ci.yml and set command ([43b96b6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/43b96b63fc2788a5ea37fa7567c6a6dced4b875f)) * update vdom-diff docs ([06590c5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/06590c56d0df7cbba68bb705cb7e159f6f765c3a)) * update xmind ([cb23933](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cb23933f46152c59a7b08f84d7355b35bba25002)) +* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380)) * update xmind ([408ca68](https://github.com/Rain120/awesome-javascript-code-implementation/commit/408ca685142dc425e90be64a284016d57d580893)) * update xmind ([4256758](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4256758c5fe0a036ce3ececc43f848e48964d7a0)) -* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380)) * update: plans; fix: readme bug ([d44e559](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d44e559def7834fcccbb19797a1d29bf5cc4e5b7)) * vdom diff algorithm ([3b7779d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3b7779dcad7e184027d1bddfa6387224c2f009d3)) * vuepress docs v1.0.0 ([785caeb](https://github.com/Rain120/awesome-javascript-code-implementation/commit/785caeb41beeff7a0f53646fc952d1c89ebb61d5)) diff --git a/package.json b/package.json index 9a180e7..6935fa2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "husky": { "hooks": { - "pre-commit": "npm run changelog && npm run deploy && lint-staged", + "pre-commit": "npm run deploy && lint-staged", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, From 9e09cf87198dfe22129ae7118e7d24966b235972 Mon Sep 17 00:00:00 2001 From: Rain120 Date: Tue, 28 Jul 2020 16:02:41 +0800 Subject: [PATCH 4/9] feat: sword means offer: 64-sum-1-n-nums --- docs/.vuepress/utils/alias.json | 3 +- .../64-sum-1-n-nums/README.md | 31 +++++++++++++++++++ .../03-find-repeat-number/README.md | 3 +- .../64-sum-1-n-nums/README.md | 27 ++++++++++++++++ .../64-sum-1-n-nums/__tests__.ts | 16 ++++++++++ .../64-sum-1-n-nums/index.ts | 20 ++++++++++++ 6 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 docs/zh/sword-means-offer/64-sum-1-n-nums/README.md create mode 100644 src/sword-means-offer/64-sum-1-n-nums/README.md create mode 100644 src/sword-means-offer/64-sum-1-n-nums/__tests__.ts create mode 100644 src/sword-means-offer/64-sum-1-n-nums/index.ts diff --git a/docs/.vuepress/utils/alias.json b/docs/.vuepress/utils/alias.json index ae6752b..987be12 100644 --- a/docs/.vuepress/utils/alias.json +++ b/docs/.vuepress/utils/alias.json @@ -54,5 +54,6 @@ "shellSort": "希尔排序", "sword-means-offer-------": "", "sword-means-offer": "剑指 Offer", - "03-find-repeat-number": "03. 数组中重复的数字" + "03-find-repeat-number": "03. 数组中重复的数字", + "64-sum-1-n-nums": "64 求1 ~ n的和" } \ No newline at end of file diff --git a/docs/zh/sword-means-offer/64-sum-1-n-nums/README.md b/docs/zh/sword-means-offer/64-sum-1-n-nums/README.md new file mode 100644 index 0000000..09d1bd5 --- /dev/null +++ b/docs/zh/sword-means-offer/64-sum-1-n-nums/README.md @@ -0,0 +1,31 @@ +### 题目描述 + +求 `1 + 2 + ... + n` , 要求 **不能使用** `乘除法`, `for`, `while`, `if`, `else`, `switch`, `case` 等关键字及条件判断语句 `(A ? B : C)` 。 +  + +示例 1: + +``` +输入: n = 3 +输出: 6 +``` + +示例 2: +``` +输入: n = 9 +输出: 45 +``` + +限制: + +1 <= n <= 10000 + +来源: [力扣 (LeetCode)](https://leetcode-cn.com/problems/qiu-12n-lcof) + +## 解题思路 or 实现原理 + +我们小学就学过 `1 + 2 + ... + n` 的结果就是 $ sum = \frac{(1 + n) * n}{2} $, 但是由于题目限定, 我们不能使用常规方法, 所以我们可以通过 **短路递归** 和 **幂运算移位** 来计算出结果。 + +## 实现代码 + +<<< @/src/sword-means-offer/64-sum-1-n-nums/index.ts diff --git a/src/sword-means-offer/03-find-repeat-number/README.md b/src/sword-means-offer/03-find-repeat-number/README.md index 26391c7..322da9a 100644 --- a/src/sword-means-offer/03-find-repeat-number/README.md +++ b/src/sword-means-offer/03-find-repeat-number/README.md @@ -1,4 +1,4 @@ -## 题目 +## 题目描述 找出数组中重复的数字。 @@ -12,7 +12,6 @@ [2, 3, 1, 0, 2, 5, 3] 输出: 2 或 3 ``` -  限制: diff --git a/src/sword-means-offer/64-sum-1-n-nums/README.md b/src/sword-means-offer/64-sum-1-n-nums/README.md new file mode 100644 index 0000000..d50ebf6 --- /dev/null +++ b/src/sword-means-offer/64-sum-1-n-nums/README.md @@ -0,0 +1,27 @@ +### 题目描述 + +求 `1 + 2 + ... + n` , 要求 **不能使用** `乘除法`, `for`, `while`, `if`, `else`, `switch`, `case` 等关键字及条件判断语句 `(A ? B : C)` 。 +  + +示例 1: + +``` +输入: n = 3 +输出: 6 +``` + +示例 2: +``` +输入: n = 9 +输出: 45 +``` + +限制: + +1 <= n <= 10000 + +来源: [力扣 (LeetCode)](https://leetcode-cn.com/problems/qiu-12n-lcof) + +## 解题思路 or 实现原理 + +我们小学就学过 `1 + 2 + ... + n` 的结果就是 $ sum = \frac{(1 + n) * n}{2} $, 但是由于题目限定, 我们不能使用常规方法, 所以我们可以通过 **短路递归** 和 **幂运算移位** 来计算出结果。 diff --git a/src/sword-means-offer/64-sum-1-n-nums/__tests__.ts b/src/sword-means-offer/64-sum-1-n-nums/__tests__.ts new file mode 100644 index 0000000..80538e7 --- /dev/null +++ b/src/sword-means-offer/64-sum-1-n-nums/__tests__.ts @@ -0,0 +1,16 @@ +/* + * @Author: Rainy + * @Date: 2020-02-06 19:05:18 + * @LastEditors: Rainy + * @LastEditTime: 2020-07-28 15:46:52 + */ + +import { sumNums_1, sumNums_2 } from '.'; + +test('Test 64-sum-1-n-nums', () => { + expect(sumNums_1(3)).toBe(6); +}); + +test('Test 64-sum-1-n-nums', () => { + expect(sumNums_2(3)).toBe(6); +}); diff --git a/src/sword-means-offer/64-sum-1-n-nums/index.ts b/src/sword-means-offer/64-sum-1-n-nums/index.ts new file mode 100644 index 0000000..61328eb --- /dev/null +++ b/src/sword-means-offer/64-sum-1-n-nums/index.ts @@ -0,0 +1,20 @@ +/* + * @Author: Rainy + * @Date: 2019-11-14 19:25:01 + * @LastEditors: Rainy + * @LastEditTime: 2020-07-28 15:42:46 + */ + +/** + * @param {number} n + * @return {number} + */ +export function sumNums_1(n: number): number { + return n && (n + sumNums_1(--n)); +}; + +export function sumNums_2(n: number): number { + // (n + 1) * n / 2 => (n ^ 2 + n) / 2 + return (n ** 2 + n) >> 1; +}; + From 27073f0aee4027321e798b0d48d900a686df5326 Mon Sep 17 00:00:00 2001 From: Rain120 Date: Tue, 28 Jul 2020 16:16:24 +0800 Subject: [PATCH 5/9] fix: plop docs code path; changelog; feat: editorconfig --- .editorconfig | 31 ++++++++++++++++++++++++++++ CHANGELOG.md | 8 ++++--- package.json | 2 +- plop-templates/code/README.md.hbs | 6 ++++-- plop-templates/docs/zh/README.md.hbs | 5 +++-- 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..05773dd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,31 @@ +# http://editorconfig.org +# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties + +# 表示是最顶层的配置文件, 发现设为true时, 才会停止查找.editorconfig文件 +root = true + +[*] +# tab space +indent_style = tab + +indent_size = 2 +# 设置换行符, 值为lf, cr, crlf +end_of_line = lf +charset = utf-8 + +# 用一个整数来设置tab缩进的列数。默认是indent_size +tab_width = indent_size + +#是否删除行尾的空格 +trim_trailing_whitespace = true + +#是否在文件的最后插入一个空行 +insert_final_newline = true + +[*.md] +indent_size = 2 +trim_trailing_whitespace = false +insert_final_newline = true + +[Makefile] +indent_style = tab diff --git a/CHANGELOG.md b/CHANGELOG.md index 551f5ed..a73f8bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,9 @@ -# 1.0.0 (2020-07-26) +# 1.0.0 (2020-07-28) ### Bug Fixes * algorithms docs build bug ([c4ed72d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/c4ed72d2da7b0f940a4f7530bdfaaa47631741ff)) -* changelog not add ([d69f43f](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d69f43f5112ea7d55242b46ca670ad54741bd940)) * ci bug ([f6185d6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/f6185d6f29e1587bba76f0772433441602bc8db7)) * deploy bug ([568b663](https://github.com/Rain120/awesome-javascript-code-implementation/commit/568b663a5fd6d1b4ab40043e0a693564d7dc3a84)) * gitalk cannot login; feat: manifest ([ee9e237](https://github.com/Rain120/awesome-javascript-code-implementation/commit/ee9e237314451244a13c6c4c13f8a119572b6ecb)) @@ -15,6 +14,7 @@ * netlify deploy bug ([f1830e9](https://github.com/Rain120/awesome-javascript-code-implementation/commit/f1830e9a07d27b4d6b9c3c67e13272e9064bb322)) * plop create code and docs model(plop name bug) ([8ef0e62](https://github.com/Rain120/awesome-javascript-code-implementation/commit/8ef0e627daadc21842de8a35495c345f9ca70550)) * readme selected; package.json husky add test ([b228b61](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b228b6194832f909c0b3c7a0c38843bab3b7c63d)) +* remove changelog at pre commit ([c49bf26](https://github.com/Rain120/awesome-javascript-code-implementation/commit/c49bf2667ff411786de3bb2442a6a4b8af9a0083)) ### Features @@ -52,11 +52,13 @@ * plop create code and docs model ([2dece76](https://github.com/Rain120/awesome-javascript-code-implementation/commit/2dece76fbfd83514551dbabadf7c54d73674730d)) * plop new code and docs template ([61a936b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/61a936b58bc52a1cf984dc6156746b43f65da7f1)) * plop new docs or template set alias; update docs about alias ([3722bcc](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3722bccea8605dfef55dd270e7f2ca14a1c03ae7)) +* plop new docs or template set alias; update docs about alias ([#21](https://github.com/Rain120/awesome-javascript-code-implementation/issues/21)) ([4334218](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4334218a4ca6635a107fe3baf2d0a17fe3e7458b)) * promise; debugger launch ([cc8ad80](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cc8ad803956e65431cedd97f1ebb333ffe78c28e)) * proxy design ([e615f39](https://github.com/Rain120/awesome-javascript-code-implementation/commit/e615f39497043f4c2357c7366cb13226b57208e6)) * sort -> bubbleSort(algorithm, readme, test) ([36fab7b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/36fab7b029d425ac129b6c4f202b18a9a3852fef)) * sort -> bucket, radix; algorithm -> binaryTree; add some types; docs: update readme; fix: tests format, ([b1d166c](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b1d166c7e56e37f35ab0bc7628186eeae15a4b60)) * sword means offer: 03 find repeat number; fix: plop template; readme title ([cf084d8](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cf084d80099aa5445bd6522a6d8be373ad2c73fb)) +* sword means offer: 64-sum-1-n-nums ([9e09cf8](https://github.com/Rain120/awesome-javascript-code-implementation/commit/9e09cf87198dfe22129ae7118e7d24966b235972)) * update docs -> algorithm: binary tree, sort ([5d57bc4](https://github.com/Rain120/awesome-javascript-code-implementation/commit/5d57bc4489551bffeca34102f2fce61b59996873)) * update docs -> design pattern function array object math primitive types utils ([1690af5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/1690af5ed96c46341465f72866732837e5c72200)) * update netlify status ([013b5ca](https://github.com/Rain120/awesome-javascript-code-implementation/commit/013b5ca5847873adabbff93a89daa41500ccf153)) @@ -64,8 +66,8 @@ * update test.yml -> ci.yml and set command ([43b96b6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/43b96b63fc2788a5ea37fa7567c6a6dced4b875f)) * update vdom-diff docs ([06590c5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/06590c56d0df7cbba68bb705cb7e159f6f765c3a)) * update xmind ([cb23933](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cb23933f46152c59a7b08f84d7355b35bba25002)) -* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380)) * update xmind ([408ca68](https://github.com/Rain120/awesome-javascript-code-implementation/commit/408ca685142dc425e90be64a284016d57d580893)) +* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380)) * update xmind ([4256758](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4256758c5fe0a036ce3ececc43f848e48964d7a0)) * update: plans; fix: readme bug ([d44e559](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d44e559def7834fcccbb19797a1d29bf5cc4e5b7)) * vdom diff algorithm ([3b7779d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3b7779dcad7e184027d1bddfa6387224c2f009d3)) diff --git a/package.json b/package.json index 6935fa2..03ea573 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "husky": { "hooks": { - "pre-commit": "npm run deploy && lint-staged", + "pre-commit": "npm run changelog && npm run deploy && git add . && lint-staged", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, diff --git a/plop-templates/code/README.md.hbs b/plop-templates/code/README.md.hbs index 553cc6a..2acc563 100644 --- a/plop-templates/code/README.md.hbs +++ b/plop-templates/code/README.md.hbs @@ -1,3 +1,5 @@ -### 解题思路 or 实现原理 +## 题目描述 -### 参考 +## 解题思路 or 实现原理 + +## 参考 diff --git a/plop-templates/docs/zh/README.md.hbs b/plop-templates/docs/zh/README.md.hbs index d7f5a76..50b614b 100644 --- a/plop-templates/docs/zh/README.md.hbs +++ b/plop-templates/docs/zh/README.md.hbs @@ -1,8 +1,9 @@ +## 题目描述 + ## 解题思路 or 实现原理 ## 实现代码 -<<< @/{{path}}/{{name}}/index.ts +<<< @/{{templatePath}}/{{name}}/index.ts ## 参考 - From bddf77de3ae3bb14bb36c6a3417edc4fd93dc6ff Mon Sep 17 00:00:00 2001 From: Rain120 Date: Sun, 9 Aug 2020 12:18:03 +0800 Subject: [PATCH 6/9] docs: update promise apply call new docs --- CHANGELOG.md | 2 +- docs/zh/es6/promise/README.md | 10 +++++++++- docs/zh/primitive/apply/README.md | 14 +++++++++++--- docs/zh/primitive/call/README.md | 10 +++++++++- docs/zh/primitive/new/README.md | 4 ++++ src/primitive/apply/README.md | 14 +++++++++++--- src/primitive/apply/index.ts | 2 +- src/primitive/call/README.md | 13 ++++++++++++- src/primitive/new/README.md | 4 ++++ src/promise/README.md | 10 +++++++++- src/promise/images/promise-resolve.png | Bin 0 -> 182200 bytes src/promise/images/promise-then.png | Bin 0 -> 112956 bytes src/promise/images/promise.drawio | 1 + 13 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 src/promise/images/promise-resolve.png create mode 100644 src/promise/images/promise-then.png create mode 100644 src/promise/images/promise.drawio diff --git a/CHANGELOG.md b/CHANGELOG.md index 78497f1..82a31dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.0.0 (2020-07-29) +# 1.0.0 (2020-08-09) ### Bug Fixes diff --git a/docs/zh/es6/promise/README.md b/docs/zh/es6/promise/README.md index 9257eb1..8740b4b 100644 --- a/docs/zh/es6/promise/README.md +++ b/docs/zh/es6/promise/README.md @@ -4,13 +4,21 @@ ![promise-process.png](@images/src/promise/images/promise-process.png) +### Then + +![promise-then.png](@images/src/promise/images/promise-then.png) + +### Promise 解决办法 + +![promise-resolve.png](@images/src/promise/images/promise-resolve.png) +

Promise Process