fork download
  1. // your code goes here
  2.  
  3. function isPalindrome(str) {
  4. // // return true if str is a palindrome else false
  5. // let tmp = "";
  6. // for(let i=str.length-1;i>=0;i--){
  7. // tmp += str[i];
  8. // }
  9.  
  10. // return tmp == str;
  11.  
  12. let left = 0, right = str.length - 1;
  13.  
  14. while(left < right){
  15. if(str[left]!=str[right]) {
  16. return false;
  17. }
  18. left++;
  19. right--;
  20. }
  21. return true;
  22. }
  23.  
  24. console.log(isPalindrome("racecar"))
Success #stdin #stdout 0.03s 18680KB
stdin
Standard input is empty
stdout
true