当前位置:网站首页>Niuke js3 separator
Niuke js3 separator
2022-07-02 17:23:00 【Drowned fish u】
describe
Please complete it JavaScript Code , The thousand separator string of the parameter number is required to be returned .
Example 1
Input :
_comma(12300)
Output :
‘12,300’
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<script type="text/javascript">
function _comma(number) {
// The completion code
// Negative judgment
let complex = false
let newStr = ''
if (number < 0) {
complex = true
}
str = number.toString()
// Split string , Return string array ['1', '2', '3', '4', '5', '6', '7']
var arr = str.split('')
// Negative judgment , remove - Number
if (complex) {
arr.shift()
}
// Invert the split string array ['7', '6', '5', '4', '3', '2', '1']
arr.reverse()
// From back to front , Add a delimiter to the array ['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, ',' )
}
}
// Invert the split string array ['1', ',', '2', '3', '4', ',', '5', '6', '7']
arr.reverse()
// Judgment of special circumstances , When the first row of the array is ',' when , remove
if (arr[0] === ',') {
arr.shift()
}
arr.map((item) => {
newStr += item })
// Negative judgment , add to - Number
if (complex) {
return '-' + newStr.toString()
} else {
return newStr.toString()
}
}
const num = _comma(1234567)
console.log(num)
</script>
</body>
</html>
边栏推荐
- GeoServer:发布PostGIS数据源
- &lt; IV & gt; H264 decode output YUV file
- ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
- Tech talk activity preview | building intelligent visual products based on Amazon kVs
- IP地址转换地址段
- Eye of depth (III) -- determinant of matrix
- 简单线性规划问题
- Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan
- Dgraph: large scale dynamic graph dataset
- The computer comes with software to make the background color of the picture transparent (matting white background)
猜你喜欢

Use of openpose

871. Minimum refueling times

Geoserver: publishing PostGIS data sources
![[web technology] 1233 seconds understand web component](/img/42/c98d8112dc4ece0a92dda97647be5c.jpg)
[web technology] 1233 seconds understand web component

2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst

Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers

ThreadLocal

A case study of college entrance examination prediction based on multivariate time series

GeoServer:发布PostGIS数据源

How to transfer business data with BorgWarner through EDI?
随机推荐
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel
【Leetcode】13. Roman numeral to integer
ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
[shutter] dart data type (dynamic data type)
Domestic relatively good OJ platform [easy to understand]
si446使用记录(二):使用WDS3生成头文件
executescalar mysql_ ExecuteScalar()
Deep learning image data automatic annotation [easy to understand]
Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
13、Darknet YOLO3
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
博客主题 “Text“ 夏日清新特别版
线性规划例题 投资的收益与风险
云通信接口更新迭代——SUBMAIL API V4正式上线
Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
IPtables中SNAT、DNAT和MASQUERADE的含义
智能垃圾桶(五)——点亮OLED
Believe in yourself and finish the JVM interview this time