Nice compact improvement! Although I would also suggest optimising for readability :-)
I did. This one was too much... :P
const getFlag=c=>String.fromCodePoint(...[...c.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt()))
You inspired me to optimise the example function in the article to have less redundant code. :-)
An alternative implementation could use the replace method to replace each character.
replace
function getFlagEmoji(countryCode) { return countryCode.toUpperCase().replace(/./g, char => String.fromCodePoint(127397 + char.charCodeAt()) ); }
This turned into a CodeWars challenge lol
Combined both of them, and I like this best. lol
(c)=>c.replace(/./g,(ch)=>String.fromCodePoint(0x1f1a5+ch.toUpperCase().charCodeAt()))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice compact improvement! Although I would also suggest optimising for readability :-)
I did. This one was too much... :P
You inspired me to optimise the example function in the article to have less redundant code. :-)
An alternative implementation could use the
replace
method to replace each character.This turned into a CodeWars challenge lol
Combined both of them, and I like this best. lol