比较不同的元素(如果我们有相同的基本字母)

jsc*_*ode 1 javascript

我想创建一个函数,允许比较某些元素, 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)

谢谢

Gho*_*med 5

使用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)