Skip to content

Diagnostic Interview Problem: Nested Loops

tim-hr edited this page Dec 5, 2016 · 1 revision

Setup

  • Make a Codestitch pad at codestitch.io.
  • Paste the problem statement into the Codestitch pad.
  • Make sure they know that they can ask questions of the interviewer.
  • Make sure they know that this is "open book". They look stuff up on the Internet (preferably staying on the MDN site).

Problem statement

var firstNames = ['Lars', 'Pejma', 'Kenji'];
var lastNames = ['Buebke', 'Jackson', 'deBoisBlanc'];

In as few lines of code as possible, generate an array containing all the combinations of first names and last names.

Notes for interviewer

If they ask about how to space out the first and last names, tell to use a single space.

Note that the point here is NOT to write a function, it is simply to write nested for-loops.

Sample answer

var fullNames = [];
for (var i = 0; i < firstNames.length; i++) {
  for (var j = 0; j < lastNames.length; j++) {
    fullNames.push(firstNames[i] + ' ' + lastNames[j]);
  }
}
console.log(fullNames);

Expectations of performance

The learner should be able to...

  • Write one for-loop.
  • Nest two for-loops.
  • Use var keyword properly.
  • Declare a string literal.
  • Concatenate strings.
  • Declare an array literal.
  • Append to an array.
  • Log data to the console after assembling the data.
  • Increment a number variable.
  • Use a comparison operator (less than).

If they cannot do ALL of these things, they are at a complete-beginner level and are likely to need extra time in the course.

Otherwise, so far we know they are likely to take an average amount of time in the course.

Clone this wiki locally