Confirm the ending of a string
Your solution is far too complicated.  It's also inefficient, because it uses functions .lastIndexOf() and .includes(), both of which analyze the entire str looking for target, whereas an optimal solution should look only starting at a known position at the end of str.

Here are two simple solutions:



function confirmEnding(str, target) {
  return str.startsWith(target, str.length - target.length);
}

function confirmEnding(str, target) {
  return target == str.substring(str.length - target.length);
}

console.log(
  false == confirmEnding("s", "try long target strings") &amp;&amp;
  false == confirmEnding("", "try an empty str") &amp;&amp;
  true  == confirmEnding("Bastian", "n") &amp;&amp;
  true  == confirmEnding("Congratulation", "on") &amp;&amp;
  false == confirmEnding("Connor", "n") &amp;&amp;
  false == confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") &amp;&amp;
  true  == confirmEnding("He has to give me a new name", "name") &amp;&amp;
  true  == confirmEnding("Open sesame", "same") &amp;&amp;
  false == confirmEnding("Open sesame", "pen") &amp;&amp;
  false == confirmEnding("Open sesame", "game") &amp;&amp;
  false == confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") &amp;&amp;
  true  == confirmEnding("Abstraction", "action")
)




The first solution, using .startsWith(), should be efficient, but it might be considered "cheating" to use .startsWith() even though only .endsWith() is prohibited.

The second solution is slightly simpler, but it involves creating a substring, so it would be less efficient.