padsize
This commit is contained in:
parent
8a9be42132
commit
06759cc8ea
30
_posts/2019-01-14-padsize.md
Normal file
30
_posts/2019-01-14-padsize.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
title: padStartにおけるpadSizeの求め方
|
||||||
|
---
|
||||||
|
|
||||||
|
$$
|
||||||
|
\textrm{padSize} = \lceil \log_{10}(\mathbf{arraySize} + 1) \rceil
|
||||||
|
$$
|
||||||
|
|
||||||
|
```js
|
||||||
|
const padSize = Math.ceil(Math.log10(arr.length + 1))
|
||||||
|
|
||||||
|
arr.forEach(async (item, index) => {
|
||||||
|
console.log(`${index.padStart(padSize, '0')}: ${item}`)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
結果は以下のようになる。
|
||||||
|
|
||||||
|
```
|
||||||
|
01: item1
|
||||||
|
02: item2
|
||||||
|
03: item3
|
||||||
|
04: item4
|
||||||
|
05: item5
|
||||||
|
06: item6
|
||||||
|
07: item7
|
||||||
|
08: item8
|
||||||
|
09: item9
|
||||||
|
10: item10
|
||||||
|
```
|
Loading…
x
Reference in New Issue
Block a user