Gather round and let me regale you with a tale of the failed interview. Truly, a tale as old as time… or as long as coding interviews have been a thing. I overall enjoy interviewing people and have had the privilege of sitting on the less stressful end of that interview table at each company I’ve joined. Most interviews follow a pretty average trajectory; and a candidate either does well or not so well and then fade into obscurity in our memory. Those that stand out are the ones who do really well, and of course those who fail spectacularly. This is a story of the latter.
I always have a difficult time deciding what interview questions I should ask during an interview but I usually choose a fairly simple exercise that will leave time for discussion and room for interpretation. In this interview I asked our interviewee, let’s call him (or her… you will never know ;) ) Chadwick, how to take an array with duplicates and return a new array with the dups removed. There are a few ways to approach the problem: sorting the array and skipping over the current item if it is equal to the next item, filtering the array by checking if the current item is already in the array holding the unique items, or using a hashmap to keep track of item counts, with the last approach being my preferred method.
Chadwick struggled to come up with any solution or approach to the problem and I suggested perhaps using some method to iterate over the array. Maybe
reduce , or
map . Chadwick looked into my eyes with a bewildered gaze, like I’d just suggested iterating over that array with a piece of gorgonzola. “Not familiar with those methods” he replied. “Oh” I said.
Outside of ES6 syntax, concepts like scope, the notorious
this keyword, global and local scope and closures are sorely missing from the toolbox of many new JS devs and can cost you an interview.
A non-exhaustive list of JS topics to cover for interviews and personal growth would be:
closures(why would we use closure? what is a practical example?). Create a function that can only be called once, leveraging closure.
filter, map, reduce(what are the differences between these array methods?). Given an array with duplicates, return an array with only the unique values.
this?). If you execute a function in the browser and console
thiswhat will it be?
- arrow functions
=>(why would we want to use one? what is the difference between fat arrow and ES5 functions?)
promises && async/awaitrefactor an asynchronous method using call backs to use the async/await pattern
Nearly every interview I’ve had has touched on a few(if not all) of these concepts and sometimes I need to refresh myself on them to overcome my jittery nerves. Chadwick, if you’re reading this, I hope our paths cross again and you demolish my stupid coding interview questions!