Interviewing for Front-End Engineers

Flattening an Array Exercise

Jem Young

Jem Young

Netflix
Interviewing for Front-End Engineers

Check out a free preview of the full Interviewing for Front-End Engineers course

The "Flattening an Array Exercise" Lesson is part of the full, Interviewing for Front-End Engineers course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to flatten an array without using ‘.flat’. Jem offers more information in answering a question and pointing to recursion as a possible means of solving.

Preview
Close

Transcript from the "Flattening an Array Exercise" Lesson

[00:00:00]
>> So this next one is, it's more race because I love the race. This next problem is one that I've gotten multiple times at many different interviews. It is without using that flat, which is a new method, which didn't exist until this year. Which will do this for you.

[00:00:20]
But without using .flat, create a function that will flatten an array. And by flattening an array it means, it's an array of arrays, of arrays, it doesn't matter how deeply nested it is. Then I want you to take out all the arrays and just give me one arrays, with all the values into one array.

[00:00:36]
Any questions on this one you would ask in an interview right now? Yes.
>> So we don't know what the structure of example array is necessarily? I mean, it is an example, but can it add more levels or less levels?
>> Yes.
>> Okay.
>> It could have no levels.

[00:00:51]
>> Okay.
>> It could just be an array of numbers. It might have 30 different arrays nested within each other. You don't know that. And this is a question that like I said, I've gotten in multiple interviews before, so chances are at some point you'll probably run into this one.

[00:01:12]
And give another hint, I shouldn't give you so many hints, using recursion for this one will help you out. It makes it easier to reason about. You don't have to use recursion. You could do it, I won't say anything else.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now