Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //use
- paddy(12,5);
- paddy(2,4,'#')
- /**
- * @param {string} value
- * @param {number} padLen length of the pad
- * @param {string} padChar character used for padding
- * @return {string} string with pad
- */
- function paddy(value, padLen, padChar) {
- var pad_char = isValid(padChar) ? padChar : '0';
- var pad = new Array(1 + padLen).join(pad_char);
- return (pad + value).slice(-pad.length);
- }
- /**
- * @param {obj} el
- * @return {boolean} true if the element in input is set
- */
- function isValid(el){
- return typeof el !== 'undefined' && el !== undefined && el !== null && el !== '';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement