LeftPad in Scala

Press + to interact
object Main {
def main(args: Array[String]) {
println(leftPad("1", 1));
println(leftPad("2", 2));
println(leftPad("3", 3));
println(leftPad("4", 4));
println(leftPad("5", 5));
println(leftPad("hello", 7));
println(leftPad("foo", 6));
println(leftPad("foo", 3));
println(leftPad("foobar", 3));
println(leftPad("foo", 6, '?'));
}
def leftPad(str:String,
paddedLength:Int,
ch:Char ='.' ) : String = {
var remLength = paddedLength - str.length;
if (remLength <= 0) {
return str;
}
val builder = StringBuilder.newBuilder
for( a <- 0 until remLength){
builder.append(ch);
}
builder.append(str);
return builder.toString();
}
}