Steamroller challenge - why is a requirement not use flat or flatMap?

Hi! I do the challenge of flat a multidimensional array, and one of the rules is, i quote: “Your solution should not use the Array.prototype.flat() or Array.prototype.flatMap() methods.”

Why is this? Is there a performance issue with that functions? Or maybe is not safe to flat a array in that way? Or is another reason?

Thanks in advance for your time and you attention.

Because flattening the array with the built in flattening methods is easy. The point here is to work on array manipulation, getting comfortable building array methods.

2 Likes

Thanks for your answer!

But i have my doubt yet: in a real world problem, using .flat(Infinity) will be the easy way to do it, right? If javascript was develop to this point with that kind of built-in methods, why we need to code in other way?

I think my question is more about the use of develop a solution like this for the real world problems but not so much for a practice environment.

1 Like

Reimplementing library functions as practice is absolutely standard when you’re learning things. This particular problem (flattening a nested list) is IME one of the most common practice problems. It can be done one of two ways – either recursively or using a stack. Both techniques are used extensively, you should be comfortable with them.

All of the algorithm problems are like this. They are all comparable directly to real-world problems because you use exactly the same techniques to solve real-world problems as you’ve learned doing these. You’re supposed to make the small mental jump and apply the techniques you’ve learned to problems you encounter IRL. They’re the same problems.

Note that almost everything in the curriculum (and any curriculum) follows this pattern. So, for example, the projects: why create an HTML tribute page, for example? What real-world application does that have when you could just use Squarespace or Wix to construct a web page using a GUI? :man_shrugging:t3:

Note also that this problem was also originally written before flat existed as a built-in function in the language. So this problem had direct real-world application (still has if you’re coding in an environment that doesn’t have access to newer features of the language).

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.