Ad
  • Custom User Avatar

    Cool! I didn't know you could leave out the ternary operator.

  • Custom User Avatar

    Smart one! I didnt know you can ommit ? value : value , good to know!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    He already told you, it's the best practice.

  • Custom User Avatar

    why won't the simplest solutions come to my mind in the first attempt......???

  • Custom User Avatar

    Seems like the most simple solution!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    My 2 cents:

    While in a "learning" perspective this would be considered "cheating" as it completely misses the (might or might not exist) lesson, it's completely irrelevant to what best practice is. Best practice is simply the most efficient and readable code, period. Showing the explicit form as the best practice teaches you to not blindly applying loops to problems all the time, just like you'd always use good external libraries and built-in objects so you wouldn't have to reimplement everything or write code in a too low-level manner. That's how programming irl works.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    First, how would deriving the series math not be the best practice (even from a learning perspective)? Loops and recursion are costly, and I find a lot of my job (software engineer) is reducing inefficiencies in hastily-written code. When presented with a series, every programmer's second thought (the first being, of course, loop or recurse this) should be, "Can I math it?" This is the 6th kyu; the training wheels are coming off, and efficiency should matter.

    Second, everyone should Google everything they don't know at all times. Heck, I derived the series math, but I ended up with an equation with respect to triangular(n + 1) that's less efficient than this one, and it took me 10 times as long to do it. I didn't learn anything doing that, I just applied what I already knew. That's a waste of my time. I could have spent that 10 minutes reading about why the series progresses the way it does, instead of just deriving a solution that works.

    In my experience, the problem with a lot of programmers is that they will bull-headedly apply what they know (loop/recurse everything!), even if it only kind of works (or works poorly), instead of finding a different, better approach (Google the series). If someone decides to copy-paste the solution without learning anything, well, that'll only get them so far, even in CodeWars. Additionally, if someone is on CodeWars, they've indicated a desire to better themselves, so I'm willing to give them the benefit of the doubt and assume most people aren't just copy-pasting.

  • Custom User Avatar

    "And yes, googling for the formula instead of taking a straightforward looping path is a good habit to have, IMO."

    I really have to disagree on this one. In the real world when you are faced with a problem that has never been solved before, "googling the solution" won't help you. I finished my electrical engineering degree a couple years ago, and the biggest problem that most of the students had was with one class where the professor would come up with innovative and challenging problems off the top of his head - and that would be the test. He allowed us to bring in any study materials we wanted: books, notes, anything except a computer or cell phone. The idea was that none of that would help you unless you had previously studied and developed a strong understanding of the basic concepts and principles from the class.

    My other classes were much less difficult, since all of the homework problems were relatively generic and you could easily find solutions on google, which most students would copy down and turn in. Same goes with the test questions. They were homework problems or book problems we had all seen before and could be solved easily having seen them before. Sure there is an ethical problem here, but with the availability of the information these days it is hard to avoid.

    Now that I am out of school, the problem I see with most graduates from my class was that they don't know how to think for themselves. They're really good at finding solutions elsewhere and applying them, or "pattern matching", which is the sort of work that is being outsourced more and more these days and is the type of work that isn't "real" engineering.

    That said, there is nothing wrong with reusing code from other people since it doesn't make sense to solve a problem that has already been solved. The most progress is made when we build off of the work of others. However, a balance needs to be found between teaching people to think through a problem and not have their first response to something unknown be "google".

    Obviously, this is a philosophical difference, but I feel it is an important issue.

  • Loading more items...