replace | function getFlagEmoji(countryCode) {
return countryCode.toUpperCase().replace(/./g, char =>
String.fromCodePoint(127397 + char.charCodeAt())
);
}
getFlagEmoji('de')
getFlagEmoji('CH')
| ready |
original | function getFlagEmoji(countryCode) {
const codePoints = countryCode
.toUpperCase()
.split('')
.map(char => 127397 + char.charCodeAt());
return String.fromCodePoint(...codePoints);
}
getFlagEmoji('de')
getFlagEmoji('CH')
| ready |
spread + reduce template | function getFlagEmoji(countryCode) {
return [...countryCode.toUpperCase()].map(char =>
String.fromCodePoint(127397 + char.charCodeAt())
).reduce((a, b) => `${a}${b}`);
}
getFlagEmoji('de')
getFlagEmoji('CH')
| ready |
spread + reduce plus | function getFlagEmoji(countryCode) {
return [...countryCode.toUpperCase()].map(char =>
String.fromCodePoint(127397 + char.charCodeAt())
).reduce((a, b) => a + b);
}
getFlagEmoji('de')
getFlagEmoji('CH')
| ready |
join | function getFlagEmoji(countryCode) {
return [...countryCode.toUpperCase()].map(char =>
String.fromCodePoint(127397 + char.charCodeAt())
).join('');
}
getFlagEmoji('de')
getFlagEmoji('CH')
| ready |
map | function getFlagEmoji(countryCode) {
const codePoints = countryCode
.toUpperCase()
.split("")
.map((char) => 127397 + char.charCodeAt(0));
return String.fromCodePoint(...codePoints);
}
getFlagEmoji('de')
getFlagEmoji('CH')
| ready |