题解 | #获取字符串的长度#
获取字符串的长度
https://www.nowcoder.com/practice/e436bbc408744b73b69a8925fac26efc
function strLength(s, bUnicode255For1) { const arr = s.split("") if(bUnicode255For1) return arr.length return arr.reduce((pre, item)=>{ pre = item.charCodeAt() > 255 ? pre + 2 : pre + 1 return pre },0) }