My code runs on Node >6.9.1 so it's really a no-brainer. The synthax is clearly superior.
I just wrote this function and used `function` rather than `=>` because I couldn't get the syntax right using an arrow function:
const showTable = ["email", "phone", "website"].reduce(
function (previous, channel) { return previous || !!institution[channel] && !/^\s*$/.test(institution[channel]); },
false
);
Of course, the inconsistencies are what I don't like about js in general. ["email", "phone", "website"].reduce(
(previous, channel) => previous || !!institution[channel] && !/^\s*$/.test(institution[channel]),
false
);
But I'd prefer the more readable: const hasNoEmail = /^\s*$/.test(institution.email || '');
const hasNoPhone = /^\s*$/.test(institution.phone || '');
const hasNoWebsite = /^\s*$/.test(institution.website || '');
const hasAny = !(hasNoEmail && hasNoPhone && hasNoWebsite); const showTable = ["email", "phone","website"]
.reduce((previous, channel) => { return previous || !!institution[channel] && !/^\s*$/.test(institution[channel])
}), false)
You can always just replace function() {
with () => {
and the only difference between the two would be binding this. Or you could do this: const showsTable = ["email", "phone", "website"]
.reduce((previous, channel) => previous || !!institution[channel] && !/^\s*$/.test(institution[channel]), false)also, I tried the solution you gave and it doesn't work :(