Correct: `Array.from()` (it’s a static method) Incorrect: `Array.join()` (doesn’t exist; it’s a prototype method) This patch uses the common `#` syntax to denote `.prototype.`.
521 B
521 B
coalesceFactory
Returns a customized coalesce function that returns the first argument that returns true from the provided argument validation function.
Use Array.prototype.find() to return the first argument that returns true from the provided argument validation function.
const coalesceFactory = valid => (...args) => args.find(valid);
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo"