1 const palindrome = str => {
2 
3   const s = str.toLowerCase().replace(/[\W_]/g,'');
4 
5   return s === s.split('').reverse().join('');
6 
7 }
8 
9 // palindrome('taco cat') -> true

将字符串转换为toLowerCase(),并使用replace()从中删除非字母的字符。然后,将其转换为tolowerCase(),将('')拆分为单独字符,reverse(),join(''),与原始的非反转字符串进行比较,然后将其转换为tolowerCase()。

相关文章:

  • 2022-02-11
  • 2021-11-01
  • 2022-01-19
  • 2022-02-17
  • 2021-11-01
猜你喜欢
  • 2022-01-07
  • 2021-08-08
  • 2021-07-28
  • 2021-05-28
  • 2021-11-15
相关资源
相似解决方案