B
B
B2o5T2018-02-03 17:01:56
JavaScript
B2o5T, 2018-02-03 17:01:56

Why does the function continue executing statements after return true?

I ran into a problem when writing a function to check a string for a polyndrom (a string that reads the same from right to left and left to right)
The function continues to work after the return true statement...
https://codepen.io/B2o5T/pen/GQobKa

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-02-03
@B2o5T

The function continues after the return true statement

No, it doesn't continue. It seems so to you, because of the recursive call. By the way, its result must also be returned, i.e. instead it
should just be
Well, there is no more check for an empty string.

P
Pavel Kornilov, 2018-02-03
@KorniloFF

function checkPalindrome(inputString) {
  var p = inputString.split(''),
    ch = p.slice().reverse();
  return p.toString() == ch.toString();
  }

  console.log (
  checkPalindrome('abcvvcba'),
  checkPalindrome('abcvcba'),
  checkPalindrome('bcbaaaa'),
  checkPalindrome('aaa')
  );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question