当前位置:网站首页>Séparateur JS3 de niuke
Séparateur JS3 de niuke
2022-07-02 17:23:00 【Poisson noyé U】
Description
Veuillez compléterJavaScriptCode,Une chaîne de séparateurs de milliers qui nécessite le retour d'un numéro de paramètre.
Exemple1
Entrée:
_comma(12300)
Produits:
‘12,300’
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<script type="text/javascript">
function _comma(number) {
// Code complet
// Jugement négatif
let complex = false
let newStr = ''
if (number < 0) {
complex = true
}
str = number.toString()
// Diviser la chaîne,Renvoie un tableau de chaînes ['1', '2', '3', '4', '5', '6', '7']
var arr = str.split('')
// Jugement négatif,Supprimer-No.
if (complex) {
arr.shift()
}
// Inverser le tableau de chaînes fractionnées ['7', '6', '5', '4', '3', '2', '1']
arr.reverse()
// De l'arrière vers l'avant, Effectuer l'opération Array add Splitter ['7', '6', '5', ',', '4', '3', '2', ',' ,'1']
for (let i = arr.length; i >= 0; i--) {
if ( i % 3 === 0 && i !== 0 ) {
arr.splice( i, 0, ',' )
}
}
// Inverser le tableau de chaînes fractionnées ['1', ',', '2', '3', '4', ',', '5', '6', '7']
arr.reverse()
// Jugement des circonstances particulières, Lorsque le premier tableau est ','Heure,Supprimer
if (arr[0] === ',') {
arr.shift()
}
arr.map((item) => {
newStr += item })
// Jugement négatif,Ajouter-No.
if (complex) {
return '-' + newStr.toString()
} else {
return newStr.toString()
}
}
const num = _comma(1234567)
console.log(num)
</script>
</body>
</html>
边栏推荐
- Briefly introduce the use of base64encoder
- Use of openpose
- Flutter: 动作反馈
- 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
- [essay solicitation activity] Dear developer, RT thread community calls you to contribute
- [fluent] dart data type map type (create map set | initialize map set | traverse map set)
- Connect Porsche and 3PL EDI cases
- 超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
- 【征文活动】亲爱的开发者,RT-Thread社区喊你投稿啦
- executescalar mysql_ ExecuteScalar()
猜你喜欢

【Leetcode】14. 最长公共前缀

使用知行之桥的API端口,提供资源供合作伙伴访问

QStyle实现自绘界面项目实战(二)

对接保时捷及3PL EDI案例

What if the default browser cannot be set?

Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers

【Leetcode】13. 罗马数字转整数

ThreadLocal

寒门再出贵子:江西穷县考出了省状元,做对了什么?
![[shutter] dart data type (dynamic data type)](/img/6d/60277377852294c133b94205066e9e.jpg)
[shutter] dart data type (dynamic data type)
随机推荐
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
远程办公对我们的各方面影响心得 | 社区征文
PCL知识点——体素化网格方法对点云进行下采样
【Leetcode】13. Roman numeral to integer
Experience home office, feel the completion of the project | community essay solicitation
剑指 Offer 26. 树的子结构
Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity
什么是敏捷开发流程
Seven charts, learn to do valuable business analysis
体验居家办公完成项目有感 | 社区征文
超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
VScode知识点——常见报错
linux安装postgresql + patroni 集群问题
IP address translation address segment
ceph 原理
chmod命令原理及用法详解[通俗易懂]
如何与博格华纳BorgWarner通过EDI传输业务数据?
剑指 Offer 22. 链表中倒数第k个节点
Shutter: action feedback