It was pretty great, when on the receiving end of that question, to be able to say, "I'm a web developer."
So now to live up to it.
function ìsZeroBalanced(n){
return (n.length === 0) ? false : true;
let x = n.reduce((a,b) => a+b, 0);
return (x===0 && n.every(y=>n.includes(-y))) ? true: false;
};
True to my resolution, I was at my desk by 8:15 this morning (even though a bit bleary-eyed, it was a late night and many drinks were bought. It was a wake. Can't toast without a beverage). And the refactoring was pretty easy. The main return statement I didn't even need to look up the syntax on MDN. The first conditional I'm not thrilled with -- currently it too is a ternary, but used inappropriately. There is never a scenario in that evaluation statement where you want a return of true. However,
return (n.length ===0) ? false;doesn't work. I don't even know what this is called in order to try to google and figure out a better way. So for now the mystery is, which is less bad, the inappropriate ternary, or
which gets at the problem of figuring this stuff out on your own. I try not to waste my mentor's time with very small questions like this. And I showed it to Asa, who said he doesn't know and currently doesn't feel like he could even do this JS challenge successfully. So it sounds like what I could use is a bigger pool of people to bother with my semi-n00b JS queries...
if(n.length === 0) return false;
Speaking of which, I've got this morning free to work on JS before having to do an interview right after lunch. Time to go learn me some JavaScript.
No comments:
Post a Comment