Re:Ask HN: If you targetting ES6 by default, how did you rat...
by iso-8859-1 on Thursday December 22, 2016 @03:24PM
(#13240091)
It's not that hard...
["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);
Re:Ask HN: If you targetting ES6 by default, how did you rat...
by charrondev on Thursday December 22, 2016 @03:28PM
(#13240109)
Well for one you're missing a closing } in that function. But you could just do
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)
Re:Ask HN: If you targetting ES6 by default, how did you rat...
by spinlock on Tuesday December 27, 2016 @07:53PM
(#13267621)
But, that's kinda my point. You shouldn't need the { for a one line function.
also, I tried the solution you gave and it doesn't work :(
Re:Ask HN: If you targetting ES6 by default, how did you rat...
by kevincennis on Thursday December 22, 2016 @05:00PM
(#13240753)
FWIW, Array.prototype.some() would probably be more idiomatic here.
I just wrote this function and used `function` rather than `=>` because I couldn't get the syntax right using an arrow function:
Of course, the inconsistencies are what I don't like about js in general.