Something went wrong. Try again.
Measure the width of text in the terminal and build simple layouts!
Something went wrong. Try again.
376 B · 16 lines
JavaScript
at main
1234567891011121314151617import { graphemeSegments } from 'unicode-segmenter/grapheme';
const str = "😀".repeat(10)
function fold_graphemes(str, state, fun) { for(const { segment: grapheme } of graphemeSegments(str)) { state = fun(grapheme, state) } return state}
let sum = 0for(let i = 0; i < 100000; ++i) { sum += fold_graphemes(str, 0, (a, b) => b + a.length)}console.log(sum)