当前位置:网站首页>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>
边栏推荐
- Eth data set download and related problems
- Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
- Eye of depth (II) -- matrix and its basic operations
- Introduction to nexus and detailed tutorial of Xiaobai using idea to package and upload to nexus3 private server
- Dstat use [easy to understand]
- What is agile development process
- 剑指 Offer 27. 二叉树的镜像
- Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
- uniapp H5页面调用微信支付
- 871. 最低加油次数
猜你喜欢

Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
![[essay solicitation activity] Dear developer, RT thread community calls you to contribute](/img/31/11409606718e0f4837f4cc572172a3.png)
[essay solicitation activity] Dear developer, RT thread community calls you to contribute

伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO

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

体验居家办公完成项目有感 | 社区征文

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

Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights

例题 非线性整数规划

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

Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
随机推荐
PCL知识点——体素化网格方法对点云进行下采样
871. Minimum refueling times
uniapp H5页面调用微信支付
Understand one article: four types of data index system
What if the default browser cannot be set?
智能垃圾桶(五)——点亮OLED
2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan
executescalar mysql_ ExecuteScalar()
Linux Installation PostgreSQL + Patroni cluster problem
Use the API port of the bridge of knowledge and action to provide resources for partners to access
Tech talk activity preview | building intelligent visual products based on Amazon kVs
The difference of message mechanism between MFC and QT
ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
Chmod command principle and usage details [easy to understand]
Ocio V2 reverse LUT
13、Darknet YOLO3
Briefly introduce the use of base64encoder
2022 interview questions
Explanation of traceroute command