Array.prototype.find()
to return the first argument that returns true
from the provided argument validation function, valid
.const coalesceFactory = valid => (...args) => args.find(valid);
const customCoalesce = coalesceFactory(
v => ![null, undefined, '', NaN].includes(v)
);
customCoalesce(undefined, null, NaN, '', 'Waldo'); // 'Waldo'
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️