Guest User

Untitled

a guest
Aug 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. function isPalindrome(a, b) {
  2. if (reverse(a) === b) return true;
  3. let str = a + b;
  4. let mid = Math.floor((str.length - 1) / 2);
  5. if (str.substring(0, mid + 1) === reverse(str.substring(mid)))
  6. return true;
  7. else return false;
  8. }
  9.  
  10. // helper function for reversing strings
  11. function reverse(str){
  12. if(str === "") return str
  13. else return reverse(str.substr(1)) + str[0]
  14. }
Add Comment
Please, Sign In to add comment