当前位置:网站首页>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>
边栏推荐
- helm kubernetes包管理工具
- ssb门限_SSB调制「建议收藏」
- Understand one article: four types of data index system
- QWebEngineView崩溃及替代方案
- 福元医药上交所上市:市值105亿 胡柏藩身价超40亿
- Use the API port of the bridge of knowledge and action to provide resources for partners to access
- ThreadLocal
- linux安装postgresql + patroni 集群问题
- Eye of depth (III) -- determinant of matrix
- Tech talk activity preview | building intelligent visual products based on Amazon kVs
猜你喜欢

Sword finger offer 25 Merge two sorted linked lists

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

Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion

Eye of depth (III) -- determinant of matrix

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)

Eth data set download and related problems

TCP拥塞控制详解 | 2. 背景

超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
随机推荐
LeetCode:1380. Lucky number in matrix -- simple
Experience home office, feel the completion of the project | community essay solicitation
人生的开始
Sword finger offer 22 The penultimate node in the linked list
class和getClass()的区别
Method of C language self defining function
JS delete substring in string
871. 最低加油次数
IPtables中SNAT、DNAT和MASQUERADE的含义
云通信接口更新迭代——SUBMAIL API V4正式上线
Briefly introduce the use of base64encoder
What is agile development process
helm kubernetes包管理工具
Introduce the scrollintoview() method attribute in detail
Eye of depth (II) -- matrix and its basic operations
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
剑指 Offer 25. 合并两个排序的链表
【Leetcode】14. 最长公共前缀
traceroute命令讲解
畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权