当前位置:网站首页>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>
边栏推荐
- Connect Porsche and 3PL EDI cases
- Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
- 【Leetcode】14. 最长公共前缀
- The impact of telecommuting on all aspects of our experience | community essay solicitation
- PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
- Flutter: 动作反馈
- Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
- The difference of message mechanism between MFC and QT
- The computer comes with software to make the background color of the picture transparent (matting white background)
- VScode知识点——常见报错
猜你喜欢

寒门再出贵子:江西穷县考出了省状元,做对了什么?

几行代码搞定RPC服务注册和发现

【Leetcode】14. 最長公共前綴

如何与博格华纳BorgWarner通过EDI传输业务数据?

Error when uploading code to remote warehouse: remote origin already exists

QWebEngineView崩溃及替代方案

ETH数据集下载及相关问题

Believe in yourself and finish the JVM interview this time

Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion

Sword finger offer 25 Merge two sorted linked lists
随机推荐
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
Eth data set download and related problems
ETH数据集下载及相关问题
871. Minimum refueling times
QStyle实现自绘界面项目实战(二)
一文看懂:数据指标体系的4大类型
Vscode + eslint configuration
&lt; IV & gt; H264 decode output YUV file
二、mock平台的扩展
VMware install win10 image
ssb门限_SSB调制「建议收藏」
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
Connect Porsche and 3PL EDI cases
ROS知识点——消息过滤器 ( message_filters)
默认浏览器设置不了怎么办?
class和getClass()的区别
What is agile development process
寒门再出贵子:江西穷县考出了省状元,做对了什么?
剑指 Offer 24. 反转链表
Error when uploading code to remote warehouse: remote origin already exists