题解 | #分隔符#
分隔符
https://www.nowcoder.com/practice/e5696992841841a8ab9d026324e4bb77
function _comma(number) { let flag = 0; if (number < 0) { flag = 1 number = -number } let a = number.toString().split('').reverse(); let s = new Array(); for (let i = 0; i < a.length; i++) { if (i % 3 == 0 && i != 0) { s.push(',') } s.push(a[i]) } if (flag == 1) { return '-' + s.reverse().join('') } return s.reverse().join('') }