Giter VIP home page Giter VIP logo

fe-interview-chaos's Introduction

前端面试大杂烩

希望可以为各位同学查缺补漏、温故知新,不希望前端学习最后成为"应试教育"

目录

欢迎互动

大家可以关注微信公众号 —— 较真的前端,来参与互动 img

贡献者

贡献者

欢迎提供你的面试题

请通过提交Issue的方式来分享你的面试题。

fe-interview-chaos's People

Contributors

royidoodle avatar saikasakura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fe-interview-chaos's Issues

0009. 实现一个全量输出promise结果(成功和失败)的方法

详细说明

实现一个方法Promise.total(Array<Promise>)。它接受的参数是由多个Promise实例构成的数组,返回值仍然是一个Promise实例。这个promise所resolve的值是传入的Array<Promise>所有结果,返回格式如下:

[
    {
        // 成功情况下,success为true,data为promise实例的决议值
        success: true,
        data: 'resolved data'
    },
    {
        // 失败情况下,success为false,data为promise实例的决绝原因
        success: false,
        data: 'rejected reason'
    }
]

示例

Promise.total([
  Promise.resolve('p1'),
  Promise.reject('p2'),
  Promise.resolve('p3')
]).then(resultList => {
    // 这里输出的是
// [
//     {
//         success: true,
//         data: 'p1'
//     },
//     {
//         success: false,
//         data: 'p2'
//     },
//     {
//         success: true,
//         data: 'p3'
//     }
// ]
    console.log(resultList);
});

应用场景

假设需要实现一个日报邮件定时推送功能,日报需要分别获取三个接口的数据,分别为订单总数、优惠券发放总数、会员总数,现在要求三个接口并发请求,三个接口都请求完成后将数据拼装并发送日报,可能会出现有接口请求失败的情况,如果失败则忽略失败数据,只发送成功获取的数据。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.