DEV Community

Discussion on: Creating Avatars With Colors Using The Modulus

Collapse
 
hoffmann profile image
Peter Hoffmann

This won't work if you user has a first letter First- or Lastname ouside [A…Z].
Better treat your name string like

name
  .substring(0,1)
  .normalize('NFKD')
  .toUpperCase()
  .charCodeAt(0)
Collapse
 
marcoslooten profile image
Marco Slooten • Edited

Thanks for replying. I'm not sure I follow, do you have an example string that doesn't work? I'm curious to check it out!

.charCodeAt(0) should work for any character that can be represented using UTF-16.

Collapse
 
hoffmann profile image
Peter Hoffmann

No, you are right, your code will always work, no matter what. I was referring to

Since we have 26 letters in the alphabet and typically two initials shown in an avatar, that means we have two spots with 26 letters, which yields 26 * 26 = 676 unique combinations.

Thread Thread
 
marcoslooten profile image
Marco Slooten

Ah I see! Yeah you're totally right, in many cases you might want to remove accent marks.