我想创建一个函数,允许比较某些元素, accélérer, Accelerer, ACCELERER...etc 并返回True作为结果(如果我们具有相同的基本字母)。
例:
compare('accélérer','ACCELERER') // will be true
compare('accélérer','accelerer') // will be true
compare('accélérer','test') // will be false
Run Code Online (Sandbox Code Playgroud)
谢谢
使用localeCompare,尝试以下操作:
const compare = (a, b) => !a.localeCompare(b, 'en' , { sensitivity: 'base'})
console.log(compare('accélérer','ACCELERER'))
console.log(compare('accélérer','accelerer'))
console.log(compare('accélérer','test'))Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |