SOURCE

function any(promises){
    const rejectedArr = [];
    let count = 0;
    return new Promise((resolve,reject)=>{
        if(promises === null || promises.length === 0){
            reject('无效的any')
        }
        for(let i=0;i<promises.length;i++){
            let p = promises[i];
            if(p&&typeof p.then === 'function'){
                p.then((data)=>{
                    resolve(data)
                },(err)=>{
                    rejectedArr[i] = err;
                    count++;
                    if(count === promsies.length){
                        reject(rejectedArr)
                    }
                })
            }else{
                resolve(p)
            }
        }
    })
}
const pErr = new Promise((resolve, reject) => {
  setTimeout(reject, 1000, "失败了");
});

const pSlow = new Promise((resolve, reject) => {
  setTimeout(resolve, 5000, "慢的成功");
});

const pFast = new Promise((resolve, reject) => {
  setTimeout(resolve, 2000, "快的成功");
});

console.log(any([pErr, pSlow, pFast]).then((value) => {
  console.log("Promise.any 成功", value);
}).catch(err =>{
  console.log("Promise.any 失败", err);
}))

console 命令行工具 X clear

                    
>
console