From dce9863c4bb52293e3cc17e0b5b8caa4120a589d Mon Sep 17 00:00:00 2001 From: Sociosarbis <136657577@qq.com> Date: Mon, 10 Jun 2019 11:22:25 +0800 Subject: [PATCH 1/4] fix:quick-sort-code-mistakes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 首先原来的295行是少了个参数的。那按照我的理解,这里应该是将随机位置元素交换到最右边。 然后重新把改过的代码运行发现sort([4,3,5,5,4,5])是会得到[3,4,5,5,4,5]的,那按照我的理解,应该需要加上308行这样,去交换小于基准值和等于基准值两者的位置。因为left是是小于等于基准值的,而less是小于基准值。 --- Algorithm/algorithm-ch.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Algorithm/algorithm-ch.md b/Algorithm/algorithm-ch.md index 4aea4602..d8676525 100644 --- a/Algorithm/algorithm-ch.md +++ b/Algorithm/algorithm-ch.md @@ -292,9 +292,9 @@ function sort(array) { function quickSort(array, left, right) { if (left < right) { - swap(array, , right) + swap(array, parseInt(Math.random() * (right - left + 1)) + left, right) // 随机取值,然后和末尾交换,这样做比固定取一个位置的复杂度略低 - let indexs = part(array, parseInt(Math.random() * (right - left + 1)) + left, right); + let indexs = part(array, left, right); quickSort(array, left, indexs[0]); quickSort(array, indexs[1] + 1, right); } @@ -305,6 +305,7 @@ function part(array, left, right) { while (left < more) { if (array[left] < array[right]) { // 当前值比基准值小,`less` 和 `left` 都加一 + less + 1 !== left && swap(array, less + 1, left); ++less; ++left; } else if (array[left] > array[right]) { From 78d5a34bf75c16c71fa065cc4a55084b7b98c6fb Mon Sep 17 00:00:00 2001 From: Sociosarbis <136657577@qq.com> Date: Mon, 10 Jun 2019 15:17:16 +0800 Subject: [PATCH 2/4] fix:fix-the-same-problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与上次修改的原因一样 --- Algorithm/algorithm-ch.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Algorithm/algorithm-ch.md b/Algorithm/algorithm-ch.md index d8676525..c653d322 100644 --- a/Algorithm/algorithm-ch.md +++ b/Algorithm/algorithm-ch.md @@ -379,6 +379,7 @@ function part(array, left, right) { let more = right; while (left < more) { if (array[left] < array[right]) { + less + 1 !== left && swap(array, less + 1, left); ++less; ++left; } else if (array[left] > array[right]) { From 7b706b33a899efe2605f027d0bc7b823ac0863b7 Mon Sep 17 00:00:00 2001 From: Sociosarbis <136657577@qq.com> Date: Tue, 11 Jun 2019 10:35:32 +0800 Subject: [PATCH 3/4] fix:predecessor-and-successor-finding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getLeft 和 getRight 如果该节点分别没有左节点和有节点,应该返回他本身吧。predecessor和successor的while的condition应该是在找到位置符合的时候停止,所以应该取反。 --- Algorithm/algorithm-ch.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Algorithm/algorithm-ch.md b/Algorithm/algorithm-ch.md index c653d322..aba1dd1a 100644 --- a/Algorithm/algorithm-ch.md +++ b/Algorithm/algorithm-ch.md @@ -646,7 +646,7 @@ function predecessor(node) { } else { let parent = node.parent // 结论 2 3 的判断 - while(parent && parent.right === node) { + while(parent && parent.right !== node) { node = parent parent = node.parent } @@ -654,9 +654,8 @@ function predecessor(node) { } } function getRight(node) { - if (!node) return - node = node.right - while(node) node = node.right + if (!node) return + while(node.right) node = node.right return node } ``` @@ -680,7 +679,7 @@ function successor(node) { // 结论 2 let parent = node.parent // 判断 parent 为空 - while(parent && parent.left === node) { + while(parent && parent.left !== node) { node = parent parent = node.parent } @@ -689,8 +688,7 @@ function successor(node) { } function getLeft(node) { if (!node) return - node = node.left - while(node) node = node.left + while(node.left) node = node.left return node } ``` From a1796b3fff7c0e8d187f9185cb0e0e6e89382a93 Mon Sep 17 00:00:00 2001 From: Sociosarbis <136657577@qq.com> Date: Wed, 12 Jun 2019 16:42:16 +0800 Subject: [PATCH 4/4] fix:MessageChannel-wrong-use-case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit new MessageChannel返回的是两个message ports,所以不能这样使用。 --- Browser/browser-ch.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Browser/browser-ch.md b/Browser/browser-ch.md index 52ba3e2e..d5dcbae1 100644 --- a/Browser/browser-ch.md +++ b/Browser/browser-ch.md @@ -163,8 +163,7 @@ CORS需要浏览器和后端同时支持。IE 8 和 9 需要通过 `XDomainReque // 发送消息端 window.parent.postMessage('message', 'http://test.com'); // 接收消息端 -var mc = new MessageChannel(); -mc.addEventListener('message', (event) => { +window.addEventListener('message', (event) => { var origin = event.origin || event.originalEvent.origin; if (origin === 'http://test.com') { console.log('验证通过') @@ -562,4 +561,4 @@ DOMContentLoaded 事件触发代表初始的 HTML 被完全加载和解析,不 - 将频繁运行的动画变为图层,图层能够阻止该节点回流影响别的元素。比如对于 `video` 标签,浏览器会自动将该节点变为图层。 - ![](https://yck-1254263422.cos.ap-shanghai.myqcloud.com/blog/2019-06-01-042737.png) \ No newline at end of file + ![](https://yck-1254263422.cos.ap-shanghai.myqcloud.com/blog/2019-06-01-042737.png)