Skip to content

Instantly share code, notes, and snippets.

@christianscott
Last active June 12, 2019 16:45
Show Gist options
  • Save christianscott/86d9fb5077ca09267b75ca5aa2ef6561 to your computer and use it in GitHub Desktop.
Save christianscott/86d9fb5077ca09267b75ca5aa2ef6561 to your computer and use it in GitHub Desktop.
How many bytes in a family emoji?
let family = 'πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§'
let codePoints = [...family]
// [ 'πŸ‘¨', '‍', 'πŸ‘©', '‍', 'πŸ‘§', '‍', 'πŸ‘¦' ]
let bytes = codePoints.map(cp => [...Buffer.from(cp)])
// [ [ 240, 159, 145, 168 ],
// [ 226, 128, 141 ],
// [ 240, 159, 145, 169 ],
// [ 226, 128, 141 ],
// [ 240, 159, 145, 167 ],
// [ 226, 128, 141 ],
// [ 240, 159, 145, 166 ] ]
let pipe = (...fns) => init => fns.reduce((val, fn) => fn(val), init)
let bytes = str => [...Buffer.from(str)]
let len = arr => arr.length
let nBytes = pipe(bytes, len)
let add = (a, b) => a + b
console.log(
[... 'πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§'].map(nBytes).reduce(add, 0)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment