Maintain Digits

This commit is contained in:
Michael Goldspinner
2018-01-11 20:45:42 -05:00
parent 38596dcaa5
commit f46518c8ae

View File

@ -0,0 +1,14 @@
### Maintain Digits
Use the modulo operator (`%`) to find values of single and tens digits.
Find which ordinal pattern digits match.
If digit is found in teens pattern, use teens ordinal.
```js
const setDigits = ( int=0, len=1, dir=0 ) => {
return dir > 0 ? int.toString().padStart(len, "0") : int.toString().padEnd(len, "0");
}
// setDigits(1, 2, 0) -> "10"
// setDigits(1, 2, 1) -> "01"
// setDigits(11, 2, 1) -> "11"
```