30-seconds-of-code

30-seconds-of-code(开发时常用的简短代码)

=

掘金中文翻译 有分类 直观一些

https://juejin.cn/post/6844903585797390344#arraymax

=

官网

https://www.30secondsofcode.org/js/p/1

=

github

https://github.com/30-seconds/30-seconds-of-code

=

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 例子
// 数字转换
// 90 => 100
// 56 => 60
getMaxNumber: function (key, array) {
let num = 0
array.forEach(ele => {
if (ele[key] > num) {
num = ele[key]
}
})
if (num <= 5) return 5
if (num > 5 && num <= 9) return 10
let all = 1000
let str = num.toString()
if (str.slice(0, 1) === '9') {
all = Math.pow(10, str.length)
} else {
all = (Number(str.slice(0, 1)) + 1) * Math.pow(10, (str.length - 1))
}
return all
},