Hi! I do the challenge of flat a multidimensional array, and one of the rules is, i quote: “Your solution should not use the
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.
Thanks for your answer!
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.
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?
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).
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.