Pad the Left or Right of a String

This pair of functions allow you to pad a string (or number) to a given length with a specified character. This might be useful in situations where you need to pad a number with leading zeroes for example.

Usage: padLeft(24, 5, '0') // Returns '00024' padRight('Foo', 10, 'b') // Returns 'Foobbbbbbb'

function padLeft(val, len, repChar) { var strReturn = val.toString; var x; 	for (x = 1; x <= num - val.toString.length; x++) { strReturn = repChar.toString + strReturn; } 	return strReturn; } function padRight(val, len, repChar) { var strReturn = val.toString; var x; 	for (x = 1; x <= len - val.toString.length; x++) { strReturn += repChar.toString; } 	return strReturn; }