题解 | #分隔符#
分隔符
https://www.nowcoder.com/practice/e5696992841841a8ab9d026324e4bb77
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n function _comma(number) {\n let numStr = ''\n //1.小于0\n if (number < 0) {\n numStr = '-'\n // 取绝对值\n number = Math.abs(number)\n }\n // 2.得到一个数组\n let arr = parseInt(number).toString().split('').reverse()\n for (let i = 3; i < arr.length; i += 3) {\n // 这里的i 没一轮循环会重新算长度 因为上次循环加了,所以i+3不够\n arr.splice(i++, 0, ',')\n }\n return numStr + arr.reverse().join('')\n \n }\n </script>\n </body>\n</html>","libs":[]}