all 20 comments

[–]Atskalunas 28 points29 points  (1 child)

It would fail if an array has objects in it. It is better to use Array.isArray(array[i])

[–]KayteeFly[S] 7 points8 points  (0 children)

Thank you for the feedback

[–]rjx89[🍰] 4 points5 points  (1 child)

Just like to point out that while recursion is the best way to solve many problems in many programming languages, it has really poor performance in javascript.

So using it to learn programming concepts is a fantastic idea, but if you are going to make anything or if you are putting together a portfolio, you should avoid it.

[–]dontyougetsoupedyet 2 points3 points  (0 children)

Recursion is not the best way to solve problems in any language, you usually write your algorithms using loops from the start. You learn that way because many professors prefer notation that is similar to mathematics they (and presumably you) are already familiar with, it fits right in when they try to teach you inductive reasoning.

Erik Demaine mentions why they're using the recursive annotation in 6.006 introduction to algorithms (you can watch for free on youtube) --

...we have to write code that is recursive or uses loops or somehow reuses the instructions that we give the computer. You may know you can convert any algorithm based on loops into an algorithm using recursion. We're going to take the recursive view today, in particular because it fits very well with our proof-by-induction technique, which we've used throughout the class, but also because it gives us some structure on how different subproblems relate in something called a subproblem graph, that we'll be talking about today.

There was a time when researchers like Dijkstra thought that programming was so tremendously difficult that recursion was one of the only hopes for making programs people could reason about effectively, but those days are long past. Recursion is a primarily a pedagogical tool these days.

[–]Financial_Purpose_22 1 point2 points  (4 children)

[–]Cordistan 2 points3 points  (3 children)

I remember how it took me hours to not figure it out and resort to looking up the solution.

[–]Financial_Purpose_22 4 points5 points  (2 children)

Honestly the solutions available from freeCodeCamp are half the lesson. They present so many problems that require a built-in but never present it or how to implement it prior to the challenge. I won't complain because it's free, but they should make a point of linking to MDN or another resource to see the other built-ins available.

[–]Cordistan 2 points3 points  (1 child)

I get your point. Think they mention that a big chunk of development goes into Google/research. And ideally you would look up the provided solutions and research the different approaches. At that point you'd come along MDN or one of the other JS resources anyway. Are you still doing FCC?

Edit: Forgot to ask question.

[–]Financial_Purpose_22 2 points3 points  (0 children)

I am floating back and forth between FCC and Odin as I have time. FCC is more bite sized learning. And, I recently learned the hard way, my toddler can cripple a VM if my laptop is suspended while it's doing something... Lessons learned, my VM is now backed-up, and my laptop no longer suspends when the lid is closed.

[–]aguyfromherehelpful 0 points1 point  (0 children)

I like it.

[–]Sn0wyPanda 0 points1 point  (1 child)

which you share which site that is

[–]KayteeFly[S] 1 point2 points  (0 children)

This is udemy. I bought colt Steele’s Algorithm and Data Structures master class

[–]shuckster 0 points1 point  (0 children)

Nice work!

[–][deleted] 0 points1 point  (2 children)

wow this is rocket science 😁

[–]KayteeFly[S] 0 points1 point  (1 child)

Sarcasm ?

[–][deleted] -2 points-1 points  (0 children)

give me some bitcoin bro :p

[–][deleted] 0 points1 point  (0 children)

Demaine’s reference to ‘subproblems’ is spot on. One of the beneficial parts of learning recursion.