标签:ring red 实现 ace form ash let reduce UNC
//正则
let cash =
‘1234567890‘
cash.replace(/\B(?=(\d{3})+(?!\d))/g,
‘,‘
);
//"1,234,567,890"
//非正则的优雅实现
function
formatCash(str) {
return
str.split(
‘‘
).reverse().reduce((prev, next, index) => {
return
((index % 3) ? next : (next +
‘,‘
)) + prev
})
}
formatCash(cash);
//"1,234,567,890"
标签:ring red 实现 ace form ash let reduce UNC
原文地址:https://www.cnblogs.com/jack123/p/12877008.html