Last active
June 12, 2019 16:45
-
-
Save christianscott/86d9fb5077ca09267b75ca5aa2ef6561 to your computer and use it in GitHub Desktop.
How many bytes in a family emoji?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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