28 Relevant Javascript Interview Questions Part I - The first 4

Ady Ngom on April 17, 2019

Cover Image: Free on Pexels by Pixabay Table of Content A little perspective 1. The Famous FizzBuzz 2. Array Method Polyfill 3. Calcu... [Read Full]
markdown guide
 

Thanks for writing this up. Obviously interviewing is broken, but I still take issue that a "correct" solution would rely on the knowledge of the existence of a specific function, i.e. sum in example two. I would hope that reduce or another efficient option would be just as acceptable. If not, it ends up being more about wrote memorization/keyword knowledge than about being able to breakdown the problem. Which is, theoretically, the point of the arduous technical interviews we have at present.

 

Hello Laurie thank you for reading and taking the time to add to the discussion. I think after reading your comment that maybe the wording of the challenge is not clear. The intent is to actually have the candidate write a sum function since it does not exist on the Array prototype methods like map, filter or reduce. In doing so the candidate should be careful in not overriding a possible future implementation of it - say for example if the method was to get added natively in ES8 or later.

For example if I was asked to add a method to the Array prototype that doubles each number in an array, a simple first step might be:

Array.prototype.doubles = function() {
 return this.map(n => n * 2);
}

And [2,4,6].doubles() will return [4,8,12].

Of course, that is the first step and there is more to it to make it more future proof - but hopefully that clarifies the intent.

Let me know if the wording needs to be revised.

Thanks again :)

 

Ah, I was gonna say, I didn't know that WAS a function on array!

I think this is the line that is a bit confusing You have been keeping up to date with new stuff in JS but are not sure that sum() is part of the Array prototype methods. That implies that it might be and you just don't know it? I might say, You have been keeping up to date with new stuff in JS and know that sum() is not part of the Array prototype methods.

I think you are right and that section might need a bit of a revision to be clearer. I will take a stab at it, feel free to propose something as well.

 

This might be a relevant question to ask


/*

  Bank notes for three different currencies are stacked in five piles per
  row(represented by the money array below).

  The task is to output to the console only those rows where the currency
  is USD AND the sum of the currency values in the five piles sums to
  100.

*/

const money = [
  {id: 0, currency: 'USD', value: [10, 20, 20, (20 + 20), 10]},
  {id: 1, currency: 'EURO', value: [10, 20, 10, 10, 10]},
  {id: 2, currency: 'USD', value: [10, 20, 20, 50, 10]},
  {id: 3, currency: 'USD', value: [20, 20, 20, 20, 20]},
  {id: 4, currency: 'GBP', value: [10, 20, 20, (20 + 20), 10]},
  {id: 5, currency: 'USD', value: [10, 20, 50, 20, 20]},
  {id: 6, currency: 'EURO', value: [5, 20, (10 + 20), (20 + 20), 5]},
  {id: 7, currency: 'USD', value: [10, 20, (10 + 20), (20 + 20), 50]},
  {id: 8, currency: 'GBP', value: [10, 20, 20, 20, 10]},
  {id: 9, currency: 'USD', value: [10, 20, (10 + 20), (20 + 20), 100]},
  {id: 10, currency: 'GBP', value: [10, 20, (10 + 20), (10 + 20), 10]},
  {id: 11, currency: 'EURO', value: [10, 20, (10 + 20), (20 + 20), 10]},
]

 

Nice thanks for the contribution. I will take a close look. I really like the wording which sounds like a good user story.
Cheers

 
 

As a developer, I've served for nearly 2 decades, always javascripting. IMO, all 4 challenges above test the modular arithmetic knowledge of a candidate. Being a direct individual, I would simply ask a candidate if they know what mod does.

I have been belittled by self proclaimed GURU's who know a few tricks (tricks are for kids!) in the interview process so many times that I've felt like the most useless developer who's ever been or will be.

In general, I'd say testing someones coding during an interview process shows how incompetent the interviewer is! Just don't do it!

code of conduct - report abuse