当前位置:网站首页>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>
边栏推荐
猜你喜欢

Understand one article: four types of data index system

深度之眼(三)——矩阵的行列式

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

Ap和F107数据来源及处理

Exploration of mobile application performance tools

The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?

Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!

一文看懂:数据指标体系的4大类型

Amazon cloud technology community builder application window opens

Eth data set download and related problems
随机推荐
简单介绍BASE64Encoder的使用
深度之眼(二)——矩阵及其基本运算
剑指 Offer 24. 反转链表
从收集到输出:盘点那些强大的知识管理工具——优秀笔记软件盘点(四)
Connect Porsche and 3PL EDI cases
Sword finger offer 25 Merge two sorted linked lists
关于我
What is agile development process
[shutter] dart data type (dynamic data type)
Meanings of SNAT, DNAT and masquerade in iptables
[web technology] 1233 seconds understand web component
Introduction to nexus and detailed tutorial of Xiaobai using idea to package and upload to nexus3 private server
海思Hi3798MV100机顶盒芯片介绍[通俗易懂]
几行代码搞定RPC服务注册和发现
ThreadLocal
871. Minimum refueling times
Believe in yourself and finish the JVM interview this time
Chmod command principle and usage details [easy to understand]
linux安装postgresql + patroni 集群问题
One year is worth ten years