4 Relevant JavaScript Interview Questions

A little perspective

For the past 12 years, I have been on both sides of the Front End Interview table. Sadly though, the emphasis is always put on Javascript during those rounds and the two other important languages — HTML and CSS — are not usually given the same weight.

Javascript though is very hard to cover as a whole since it has evolved from inside the DOM manipulation frame, to about anything that one sets their mind too. Let’s not even mention the plethora of Javascript libraries and frameworks that have sprouted all around like an army of bunnies following a long and harsh winter — Spring is coming!!

All jokes aside though, you could totally rock it at one interview and feel like you command the clouds, or be harshly knocked off the mountain tops in another.

The interview process as a whole is busted and has been a source of frustration for both the candidate and the companies trying to hire the right talent.

I have decided to add my modest contribution and I’m hoping to be a part of the solution here. I have been literally reading over hundreds of common interview questions and feel like a review and refactor of those are the key elements in fixing the bigger issue, but I need your help :)

I will be sharing a curated list of the ones that I have picked, adapted and sometimes created as most relevant to not only for a candidate to prepare but also for a company to assess one. It is obviously very opinionated but will hopefully become valuable and maybe a standard with the help and inputs from the JS community.

Below is the first batch of 4, take a read and let me know how you feel about all or some of them in the comments. I highly encourage you to contribute by proposing some possible interview questions in the comments. Please share with anyone who can add to or benefit the discussion.

#1. The Famous FizzBuzz

Best suited for: Junior | Senior Stage: Round 1 | All rounds

1A. — The Challenge

Write a program that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz

1B. The context

The FizzBuzz challenge is not specific to JavaScript and has been part of the coding interview process in almost every programing language. It is usually a quick check to assess the candidate basic programming instincts, but can also be turned in an assessment for in-depth knowledge if the interviewer decides to do so.

It is usually part of a lightweight first technical interview done while screen sharing. It is also a favorite from a non-JavaScript programmer to ask and quickly gauge your technical knowledge and approach.

In a Javascript context familiarity with some or all the following concepts are expected to be demonstrated:

  • Logical operators
  • Looping
  • Falsy values
  • Ternary operator
  • Type coercion

#2. Array Method Polyfill

Best suited for: Junior | Senior Stage: Round 2 | Onsite

2A. The challenge

You might have to add all items in an array of numbers. 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.

Write a small program that will add all the items in an array of numbers and return the total using the Array sum function if it exists or using your custom function.

// should output 21
[1,2,3,4,5,6].sum();
// should be chainable and also output 21
[1,2,3].concat([4,5,6]).sum();

2B. The context

Extending native objects is usually frowned upon in JS circles. This should stir a ‘healthy’ debate on the pros and cons of doing so. Ultimately, it should highlight the candidate awareness of safeguarding against potential existing and future functionality override. I believe it’s a good question for a code screening or the first question on an onsite interview.

#3. Calculate Employee Gross Pay

Best suited for: Senior | Expert Stage: Round 2 | Round 3 | Onsite

3A. The challenge

As a new member of the Kora Inc. development, your new hot assignment is to help the HR department quickly calculate employees gross pay. Below are the compensation models for each role:

const associate = { roleId: 3, rate: 12.5,overtime: 18.75 };
const supervisor = { roleId: 2, rate: 15,overtime: 22.5 };
const admin = { roleId: 1, rate: 30, overtime: 0 }; // salary no overtime

Write a base function that takes a role (object), hours (number) and ovtHours (number) as arguments and returns the employee gross pay.

Using this base function, create three partial application functions that respectively will calculate the associate, supervisor or admin gross pay when invoked.

3B. The context

From a first look, putting a function or program to calculate gross pay is very straightforward. Here, as I’m screening the candidate, I will pay close attention to her/him taking the time in reading about the specificity of the solution asked.

I will expect to have a lot of questions around the terms base function and the concept of partial application. I will also not push for in-depth knowledge of functional programming concepts such as currying but I will expect a general awareness of those.

#4. Rolls of coins

Best suited for: Junior | Senior | Expert Stage: Round 2 | Round 3

4A. The challenge

At the end of her shift, Amina’s tip jar is full of coins. She needs a little help in counting and stocking her hard earned loot. She wants to organize her coins in rolls so it is easy to bring back to the bank.

Write a program that will help her quickly find out how many rolls she has for each coin denomination and the remainder on each.

Below is a table of how many coins should be in each roll per denomination:

Screen Shot 2019-04-17 at 10.36.29 AM.png

Your program will accept an unsorted array of coins. You can assume that each coin will be either 1, 5, 10 or 25. It should print a message like the one below:

  • Pennies: 10 rolls — 39 left
  • Nickels: 25 rolls — 0 left
  • Dimes: 12 rolls — 49 left
  • Quarter: 2 rolls — 20 left

4B. The context

This one is a slight twist and variation of the Socker Merchant Challenge — Hacker Rank.

It is a frequency count as an exercise and since it can be approached and solved a countless number of ways, it is a perfect pick to get the candidate to walk us through their approach and their iterative process in problem-solving.

I’m a huge proponent of the ‘Make it work first, optimize and refactor later’ approach. I would pay close attention to code that overall is readable and self-documenting.

In closing

Alright folks, this was quite a long post and I salute you if you have made it this far. Let’s keep the discussion live in the comments. Part 2 is soon to follow.

Cheers

Comments (7)

Vikas Poonia's photo

Thanks for the questions. But I have a question does interviewer helps interviewee in a quest of finding a solution to the problems or is it just a latter has to figure it out by himself apart from some syntax help.

Show all replies
Ady Ngom's photo

Solutions Designer JS Tech Lead Consultant at EY

You welcome anytime

Joshua Alpuerto's photo

Hi,

Great Article!

I'm just confused with this instruction on #3. Calculate Employee Gross Pay

Using this base function, create three partial application functions that respectively will calculate the associate, supervisor or admin gross pay when invoked.

I don't think it needs partial application for calculating those 3 roles since the base functions accepts role object already. But it can help to create partial application when computing the grossPay for the total of hourly and overtime.

const getGross = (rate) => (totalHours) => rate * totalHours
const computeGrossSalary = ({
  role = {}, 
  totalHours = 0,
  overtimeTotalHours = 0                        
}) => {
  const { rate: hourlyRate = 0, overtime: overtimeRate = 0 } = role || {}
  const totalHourlySalary = getGross(hourlyRate)
  const totalOvertimeSalary = getGross(overtimeRate)

  return totalHourlySalary(totalHours) +  totalOvertimeSalary(overtimeTotalHours)
}

computeGrossSalary({
  role: { roleId: 3, rate: 12.5, overtime: 18.75 },
  totalHours: 1
})

BTW I know it's bad to assume and should ask the interviewer if not clear. But I assume that the rate is hourly not daily.

Please correct me if am wrong.

Cheers!

Show all replies
Joshua Alpuerto's photo

Full Stack | NodeJS | React | PHP | React-Native | Web | Mobile

Thanks for your response.

The computation of gross can be a partial application since it can be reused, this also helps for readability.

Thanks in advance for your feedback.