Files
30-seconds-of-code/snippets/coalesce.md
2017-12-17 11:39:24 -08:00

233 B

Coalesce a set of arguments

Use find() to return the first non null/undefined argument.

const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_))
// coalesce(null,undefined,"",NaN, "Waldo") -> ""