The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Create an Array concatAll method

Create an Array concatAll method

4:17
In addition to flat Arrays, programmers must often deal with nested Arrays. For example let's say we have an Array of stock exchanges, each of which is represented by an array of all the stocks listed on that exchange. If we were looking for a stock that matched a certain criteria, we would first need to loop through all of the exchanges, and then all of the stocks within. In these situations, most developers would nest two loops. However in this lesson we will write a new Array function "concatAll" which will automatically flatten nested arrays buy one dimension. This will remove the need to ever use a nested loop to flatten a nested array.
Watch this lesson now
Avatar
egghead.io

In addition to flat Arrays, programmers must often deal with nested Arrays. For example let's say we have an Array of stock exchanges, each of which is represented by an array of all the stocks listed on that exchange. If we were looking for a stock that matched a certain criteria, we would first need to loop through all of the exchanges, and then all of the stocks within.

In these situations, most developers would nest two loops. However in this lesson we will write a new Array function "concatAll" which will automatically flatten nested arrays buy one dimension. This will remove the need to ever use a nested loop to flatten a nested array.

Avatar
Kevin

I've been in discussions and code reviews where some "senior" developers would frown upon nested foreach loops.

Could you give any insight into why this would be a bad thing? Maybe I misunderstood and he meant the for loop, not forEach(). Either way, it would be interesting to hear your opinion.

Cheers.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?