contry (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
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
new
function getFlagEmoji(countryCode) {
  return [...countryCode.toUpperCase()].reduce((accumulator, char) => 
      accumulator + String.fromCodePoint(127397 + char.charCodeAt()), '');
}
getFlagEmoji('de')
getFlagEmoji('CH')
ready
reverse
function getCountryCode(flagEmoji) {
  const codePoints = [...flagEmoji].map(char => char.codePointAt(0));
  const countryCode = String.fromCharCode(...codePoints.map(codePoint => codePoint - 127397));
  return countryCode.toLowerCase();
}
getCountryCode('🇩🇪')
getCountryCode('🇨🇭')
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.