promise.reject()

EasyMeta

Prompt

Write a function promiseReject(reason) that behaves like Promise.reject(). It should return a promise that is immediately rejected with the given reason.

If reason is already a promise, it should still be used as the rejection reason (not unwrapped).

promiseReject('error').catch((err) => console.log(err));
// 'error'
promiseReject(42).catch((err) => console.log(err));
// 42
promiseReject(new Error('fail')).catch((err) =>
console.log(err.message)
);
// 'fail'