4 ms·
My code runs on Node >6.9.1 so it's really a no-brainer. The synthax is clearly superior.
by simlevesque 10y ago
My code runs on Node >6.9.1 so it's really a no-brainer. The synthax is clearly superior.
- spinlock 10y agoYou know what's weird, I don't like the arrow functions in es6. And, I'm a coffeescript guy. I just don't like that the syntax is conditional on so many different things. The number of parameters, line length, etc... 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.
- iso-8859-1 10y agoIt'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);
- charrondev 10y agoWell 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)
- spinlock 10y agoBut, 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 :(
- kevincennis 10y agoFWIW, Array.prototype.some() would probably be more idiomatic here.
- spinlock 10y agoWhere were you on my code review :) Great suggestion.