From 67dce85970b0e9e7cc7350300f46c37b669c6c0f Mon Sep 17 00:00:00 2001 From: wanggenzhen Date: Thu, 27 Aug 2020 15:49:39 +0800 Subject: [PATCH] day127 add --- README.md | 38 +++++++++++++++++++++++++++++++++++--- summarry/all.md | 2 +- summarry/daily.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a215ac..007f64f 100755 --- a/README.md +++ b/README.md @@ -46,9 +46,41 @@ > 每天get一个知识点 -### Day126:请描述 CSRF、XSS 的基本概念、攻击原理和防御措施? - -**[答案&解析](https://github.com/lgwebdream/FE-Interview-Planet/issues/939)** +### Day127:按要求完成 mergePromise 代码 + +```js +const timeout = (ms) => + new Promise((resolve, reject) => { + setTimeout(() => { + resolve(); + }, ms); + }); +const ajax1 = () => + timeout(2000).then(() => { + console.log("1"); + return 1; + }); +const ajax2 = () => + timeout(1000).then(() => { + console.log("2"); + return 2; + }); +const ajax3 = () => + timeout(2000).then(() => { + console.log("3"); + return 3; + }); +const mergePromise = (ajaxArray) => { + // 1,2,3 done [1,2,3] 此处写代码 请写出ES6、ES3 2中解法 +}; +mergePromise([ajax1, ajax2, ajax3]).then((data) => { + console.log("done"); + console.log(data); // data 为[1,2,3] +}); +// 执行结果为:1 2 3 done [1,2,3] +``` + +**[答案&解析](https://github.com/lgwebdream/FE-Interview-Planet/issues/940)**
diff --git a/summarry/all.md b/summarry/all.md index a908c3c..9896bee 100755 --- a/summarry/all.md +++ b/summarry/all.md @@ -8916,7 +8916,7 @@ person.method(fn, 1); ### React SSR实现过程?原理是什么?有什么注意事项? -分类:Node +分类:React [答案&解析](https://github.com/lgwebdream/FE-Interview/issues/869) diff --git a/summarry/daily.md b/summarry/daily.md index 8ca877f..504afa3 100755 --- a/summarry/daily.md +++ b/summarry/daily.md @@ -1910,3 +1910,45 @@ console.log(a.b) [答案&解析](https://github.com/lgwebdream/FE-Interview-Planet/issues/939)
+ +### Day127:按要求完成 mergePromise 代码 + +```js +const timeout = (ms) => + new Promise((resolve, reject) => { + setTimeout(() => { + resolve(); + }, ms); + }); +const ajax1 = () => + timeout(2000).then(() => { + console.log("1"); + return 1; + }); +const ajax2 = () => + timeout(1000).then(() => { + console.log("2"); + return 2; + }); +const ajax3 = () => + timeout(2000).then(() => { + console.log("3"); + return 3; + }); +const mergePromise = (ajaxArray) => { + // 1,2,3 done [1,2,3] 此处写代码 请写出ES6、ES3 2中解法 +}; +mergePromise([ajax1, ajax2, ajax3]).then((data) => { + console.log("done"); + console.log(data); // data 为[1,2,3] +}); +// 执行结果为:1 2 3 done [1,2,3] +``` + +公司:阿里 + +分类:JavaScript、编程题 + +[答案&解析](https://github.com/lgwebdream/FE-Interview-Planet/issues/940) + +