0

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

Khaled Ayed
  • 1,121
  • 3
  • 12
  • 29
  • Do you want to treat "é" and "e" as the same letter? And do you distinguish cases (uppercase and lowercase)? – SparkFountain Aug 22 '19 at 13:07
  • 1
    Possible duplicate of [Remove accents/diacritics in a string in JavaScript](https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript) – I wrestled a bear once. Aug 22 '19 at 13:10
  • Sounds easy enough, (stringA.toLowerCase().replace("é", "e").compare(stringB.toLowerCase().replace("é", "e")) == 0) ? true : false; – SPlatten Aug 22 '19 at 13:10

1 Answers1

4

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'))
SparkFountain
  • 2,110
  • 15
  • 35
Ghoul Ahmed
  • 4,446
  • 1
  • 14
  • 23