题解 | #分隔符#
分隔符
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 // 补全代码\n let s = number + '';\n let a = s.split(\"\");\n let k = 0;\n let re = [];\n let p=false\n if(a[0]==\"-\"){\n p=true;\n a.shift();\n };\n for (let i = a.length - 1; i > -1; i--) {\n re.unshift(a[i]);\n k += 1;\n if (k == 3 && i != 0) {\n re.unshift(\",\");\n k = 0;\n }\n }\n if(p){\n re.unshift(\"-\")\n }\n return re.join(\"\")\n\n }\n </script>\n </body>\n</html>","libs":[]}
我是喜欢使用数组的unshift /shift