How to write palindrome in JavaScript

前端 未结 30 1818
情书的邮戳
情书的邮戳 2020-11-29 02:42

I wonder how to write palindrome in javascript, where I input different words and program shows if word is palindrome or not. For example word noon is palindrome, while bad

30条回答
  •  一个人的身影
    2020-11-29 03:44

    Here's another way of doing it:

    function isPalin(str) {
      str = str.replace(/\W/g,'').toLowerCase();
      return(str==str.split('').reverse().join(''));
    }
    

提交回复
热议问题