Appearance
检验一个字符串是否是回文
备注
该方法只适用于单词或短句的回文检查,而不适用于包含标点符号、空格或多行文本的情况。
语法
js
import { isPalindrome } from 'warbler-js';
const result = isPalindrome(str);
参数
str
(String) : 需要检验的字符串。
返回值
Boolean : true
是回文 ,false
不是回文。
源码
js
const isPalindrome = (str) => str === [...str].reverse().join('');
例子
js
import { isPalindrome } from 'warbler-js';
const str = 'abcdedcba';
const result = isPalindrome(str);
console.log(result); //=> true
添加版本
1.2.2