-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3260bb
commit 961b6ea
Showing
13 changed files
with
1,055 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ _book/ | |
.DS_Store | ||
./docs/.vuepress/dist | ||
/dist/ | ||
/temp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
303. 区域和检索 - 数组不可变 | ||
|
||
使用前缀和,提高检索速度,时间复杂度为 O(1). | ||
|
||
```js | ||
/** | ||
* @param {number[]} nums | ||
*/ | ||
var NumArray = function(nums) { | ||
let n = nums.length; | ||
this.sums = new Array(n + 1).fill(0); | ||
for (let i = 0; i < n; i++) { | ||
// sums[i]表示 nums 从下标 00 到下标 i-1i−1 的前缀和。 | ||
this.sums[i + 1] = nums[i] + this.sums[i]; | ||
} | ||
}; | ||
|
||
/** | ||
* @param {number} left | ||
* @param {number} right | ||
* @return {number} | ||
*/ | ||
NumArray.prototype.sumRange = function(left, right) { | ||
return this.sums[right + 1] - this.sums[left]; | ||
}; | ||
``` | ||
|
||
前缀和主要适用的场景是原始数组不会被修改的情况下,频繁查询某个区间的累加和。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 思路 | ||
|
||
二叉搜索树,中序遍历是升序的。重复的数字一定是连续的,可以转变为,求有序数组中的众数。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
### 目录 | ||
- [实现一个防抖](./防抖.md) | ||
- [手写一个节流](./节流.md) | ||
- [浅比较和深比较](./浅比较和深比较.md) | ||
- [浅拷贝和深拷贝](./浅拷贝和深拷贝.md) | ||
- [数组乱序](./数组乱序.md) | ||
- [函数柯里化](./函数柯里化.md) | ||
- [实现一个Promise](./实现一个Promise.md) | ||
- [实现一个new](./实现一个new.md) | ||
- [实现instanceof](./实现instanceof.md) | ||
- [手写继承](./手写继承.md) | ||
- [实现一个async函数](./实现一个async函数.md) | ||
- [实现一个iterator](./实现一个iterator.md) | ||
- [setTimeout实现setInterval](./setTimeout实现setInterval.md) | ||
- [限制并发请求](./限制并发请求.md) | ||
- [简单实现一个Vue的双向绑定](./简单实现一个Vue的双向绑定.md) | ||
- [实现一个vue自定义指令-懒加载](./实现一个vue自定义指令-懒加载.md) | ||
- [实现一个轮播图](./实现一个轮播图.md) | ||
- [实现一个放大镜效果](./放大镜效果.md) | ||
## 目录 | ||
|
||
通过题目来学习一些 javaScript 基础知识 | ||
|
||
### API 实现 | ||
|
||
- [实现一个 new](./实现一个new.md) | ||
- [实现 instanceof](./实现instanceof.md) | ||
- [实现一个 iterator](./实现一个iterator.md) | ||
- [setTimeout 实现 setInterval](./setTimeout实现setInterval.md) | ||
- [写 call,apply,bind](./手写call,apply,bind.md) | ||
- [实现一个 EventEmitter](./发布-订阅模式的实现.md) | ||
|
||
### 功能函数实现 | ||
|
||
- [手写继承](./手写继承.md) | ||
- [实现一个防抖](./防抖.md) | ||
- [手写一个节流](./节流.md) | ||
- [浅比较和深比较](./浅比较和深比较.md) | ||
- [浅拷贝和深拷贝](./浅拷贝和深拷贝.md) | ||
- [数组乱序](./数组乱序.md) | ||
- [函数柯里化](./函数柯里化.md) | ||
|
||
### 数据结构转换 | ||
|
||
### Promise 异步相关 | ||
|
||
- [实现一个 Promise](./实现一个Promise.md) | ||
- [实现一个 async 函数](./实现一个async函数.md) | ||
- [限制并发请求](./限制并发请求.md) | ||
- [实现一个 LazyMan](./LazyMan.md) | ||
- [koa 洋葱模型 compose](./洋葱模型compose) | ||
- [实现一个 repeat 方法](./实现一个repeat方法.md) | ||
|
||
### 功能实现 | ||
|
||
- [简单实现一个 Vue 的双向绑定](./简单实现一个Vue的双向绑定.md) | ||
- [实现一个 vue 自定义指令-懒加载](./实现一个vue自定义指令-懒加载.md) | ||
- [实现一个轮播图](./实现一个轮播图.md) | ||
- [实现一个放大镜效果](./放大镜效果.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 参考 | ||
|
||
- [compose 函数和 pipe 函数](http://dennisgo.cn/Articles/JavaScript/ComposePipe.html) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## koa 的洋葱模型 | ||
|
||
```js | ||
app.use((next) => { | ||
console.log(1); | ||
next(); | ||
console.log(4); | ||
}); | ||
app.use((next) => { | ||
console.log(2); | ||
next(); | ||
console.log(5); | ||
}); | ||
app.use((next) => { | ||
console.log(3); | ||
next(); | ||
console.log(6); | ||
}); | ||
app.compose(); | ||
// 输出是123654; | ||
``` | ||
|
||
当程序运行到 next()的时候就会暂停当前程序,进入下一个中间件,处理完之后才会回过头来继续处理。 | ||
|
||
核心:中间件管理和 next 实现,其中 next 是巧妙的使用了 Promise 特性。洋葱模型,本质上是 Promise.resolve()的递归。 | ||
|
||
## 参考 | ||
|
||
- [Koa 洋葱模型原理分析](https://lq782655835.github.io/blogs/node/koa-compose-modal.html) | ||
- [Koa2 洋葱模型 —— compose 串联中间件的四种实现](https://segmentfault.com/a/1190000016707187) |
Oops, something went wrong.