Confirm the Ending

This post is more about how to think to resolve it. I had troubles initially and the breakthrough was when I started to subdivide the problem into simple tasks :

  • read target
  • count the target characters number
  • take same number of characters from the end of the str and make a new string from them
  • compare that new string with target string
    -if equal ==> true
  • if not equal ==> false

What I took from this is that I was doing all wrong during the entire course up until now because I was trying to solve it globally, as a single question to find the answer to.
So in case there are others doing this same mistake please try to do this instead. It is so much better. Took me like 2 hours yesterday, doing it the “wrong” way and just 10 minutes today to solve the exercise.

P.S. this is my result:

function confirmEnding(str, target) {

  let Ending = str.slice(-target.length);
  if (target === Ending) {
    return true;
  else {
    return false;

  return str;

confirmEnding("Bastian", "n");

We have blurred this solution (with [spoiler][/spoiler] tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

Yeah, being able to break problems into smaller problems (and sometimes breaking those into smaller problems, etc.) is an important thing. And being able to think about problems abstractly, without thinking about specific code, is good, too. You could even go so far as writing out pseudo code.

1 Like

Thanks, I had to look up the internet to learn what pseudo code is :slight_smile:
Good idea, will try.

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