function formatCash(str) {
return str.split('').reverse().reduce((prev, next, index) => {
return ((index % 3) ? next : (next + ',')) + prev
})
}
document.write(formatCash('1234567890')) // 1,234,567,890
<div>js 笔试题目: 优雅的实现 金钱格式化</div>