Khaled Ayed
Khaled Ayed

Reputation: 1277

compare different elements (if we have the same base letter)

I want to create a function allow to compare some elements like accélérer, Accelerer, ACCELERER...etc and return True as result (if we have the same base letter).

example:

compare('accélérer','ACCELERER')  // will be true
compare('accélérer','accelerer')  // will be true
compare('accélérer','test')  // will be false

thanks

Upvotes: 0

Views: 101

Answers (1)

Ghoul Ahmed
Ghoul Ahmed

Reputation: 4806

Use localeCompare, try this:

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'))

Upvotes: 4

Related Questions