Friday, October 27, 2017

Day 2: Refactoring for fun and smartness

So last night I went to the closing party for the alternative newsweekly where I worked for two decades, the Baltimore City Paper. Many if not most of my colleagues were there, and there was much catching up. Some of us are yet staying the course upon the uneasy waters of professional journalism, but at least half the people I spoke with have moved on to new careers. Many of them, when asked the inevitable "So hey what are you doing now?", responded with downcast eyes and a description on some variation of a PR or marketing job.

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

if(n.length === 0) return false;
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...

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