Confirm the Ending algorithms solving

Tell us what’s happening:
Hey Devs! I am having issues in algorithms solving , can you please tell me / recommend me any book to read and master algorithms . Thank in advance

  **Your code so far**

function confirmEnding(str, target) {

//we turn our str and arr to an array
let arrStr = str.split("");
let tarStr = target.split("");
let lengthStr = arrStr.length;
let lengthTar = tarStr.length;
//we check if the last index is equal to the target
if(arrStr[lengthStr-1] === tarStr[lengthTar-1]){
  if(arrStr.includes("n") > 2){
    return false;
    return true;
else if(arrStr[lengthStr-1] !== tarStr[lengthTar-1]){
  return false;
//if it is equal to the target we should return true
//else false


confirmEnding("Bastian", "n");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.

Challenge: Confirm the Ending

Link to the challenge:

I think you are making things too complicated. This can be solved with very few lines of code (one line is easily possible). I would take a hint from the instructions:

“we would like you to use one of the JavaScript substring methods instead”

This is telling you there is a String method which you can use that will make this solution very simple. I’m not sure if FCC has introduced this method (my gut says yes) but it will allow you to slice up all of the code you currently have into one nice and tidy solution.

1 Like

I think mastering algorithms is about just doing a lot of them. You absorb them and they enter your algorithmic vocabulary. A lot of it is just learning to think in different ways and learning some tricks.

I think just doing them is good. Then, after you’ve solved them, see how others have solved it - google it, check youtube, etc.

That being said, I think Cracking the Coding Interview is a classic book. I haven’t read The Art of Computer Programming yet, but Knuth is brilliant so I assume the book is too.


Thank you so much! @bbsmooth You are right I was making things too complicated.

Thanks for the suggestion @kevinSmith, I will try to do as you said! I think that mastering algorithms and data structure are more important than learning all new technologies.

I don’t think it is “more important”. I would say that most of the time, learning new techs might get you a job more often.

Algorithms and data structures are cool. They can be fun. For some jobs they are very important. But I think sometimes they get an overemphasis. They can be a cock way to show off in brogrammer culture. And in job interviews they can be an easy way to test someone.

But there is a lot to being a developer and they are only a piece, and not even close to the most important, imho. They are good to learn: they can be challenging, fun, stretch your “coder brain”, impress your friends, impress your interviewer… And they do come in handy sometimes. But don’t think they are the met important thing. Think of them as a a life long side project. Work on them, but don’t obsess, and don’t let it get in the way of becoming a developer. It would be like an author thinking that the most important thing is to master grammar.

1 Like

Totally agree with you! @kevinSmith, the thing is that every day they rise new technologies, but if you are good at algorithms and data structures you can master any technology and any programming language, (it’s like the most you master grammar is the most you master the language)! correct me if am wrong!

I’m sorry, but I disagree with that statements. In my experience (#ymmv) in three years as a professional developer, I think I have only twice had to deal with what I would call a “hard algorithm”, and even those weren’t particularly difficult. There are a lot of little algorithm things, but they were so trivial that most people don’t even recognize them as algorithms.

Algorithms are one aspect of programming. Some of the best developers with whom I’ve had the pleasure of working weren’t particularly great at algorithms. If I had to chose between a developer who “mastered” algorithms but nothing else and one who “mastered” everything else, I will choose the second person, every time, without hesitation.

the thing is that every day they rise new technologies,

Which is why it’s even more important to try to keep current, or even a few years behind. Algorithms are constant so you can just work on them as you go, but technologies are slowly evolving.

There is a principle in business that benchmarks that can be easily measured are given more disproportionate weight over things that are difficult to measure. Algorithms are really easy to test people on and to measure their success, so people think that that makes them very important. They are important, but they are far from the most important.

It reminds me of a job interview I had where they pounded me on algorithms. I did OK and when we talked after that portion of the interview, I asked them what kind of work I would be doing. They listed a lot of stuff. I commented that the coding part of the interview was entirely algorithms of trees (a kind of data structure). I asked if they did a lot of that stuff. He laughed and said, “God no, I can’t remember ever having to do a tree, here or anywhere else.” People put a disproportionate weight on them because they are easy to measure and because they think they are supposed to.

And I have met plenty of junior devs who were terrible at algorithms. I worked with a guy who had no idea what recursion was, even after I explained the concept. Another guy had never heard of a factorial. On a PR review someone was using a JS find to find a value in an enormous array. I suggested a binary search - he had no idea what I meant. When I coded it out for him in a few lines, he thought I was a magician - I had to keep explaining it to him. That is a very simply algorithms, one of the first ones I learned, one that some might not even think of as an algorithm because it is so simple (It’s basically what we do when we look for a name in the phone book.)

Work on them, but think of them as a long term project and realize that learning techs, building things, etc. - are much more important in the long run.

I agree with @kevinSmith! Thanks for your feedback! I appreciate it! You got a point :+1: :heavy_check_mark: :white_check_mark:

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