반응형
function numberPad(n, width) {
    n = n + '';
    return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
}

위 함수는 3을 03으로 표현하고 싶을때,

 

numberPad(3, 2); 를 입력하면 3 -> 03으로 return 되게 됩니다.

 

출처 : https://matthew-jo.tistory.com/8

반응형

+ Recent posts