How to write palindrome in JavaScript

前端 未结 30 1797
情书的邮戳
情书的邮戳 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:19

    Try this

    isPalindrome = (string) => {
        if (string === string.split('').reverse().join('')) {
            console.log('is palindrome');
        }
        else {
            console.log('is not palindrome');
        }
    }
    
    isPalindrome(string)
    

提交回复
热议问题