Promise.prototype.race = function(promises) {
return new Promise((resolve, reject) => {
if (!isArray(promises)) {
return reject(new TypeError('Arguments not Array'));
}
for (let p of promises) {
Promise.resolve(p).then(
res => resolve(res),
rej => reject(rej)
)
}
})
}