LeftPad in Go
We'll cover the following...
Press + to interact
package mainimport "fmt"import "strings"func leftPad(str string,paddedLength int,ch string) string {if len(ch) != 1 {fmt.Println("Invalid Input, Throw here")return str}if len(str) > paddedLength {return str}paddedLength = paddedLength - len(str)return strings.Repeat(ch, paddedLength) + str}func main(){fmt.Println(leftPad("1", 1, "."))fmt.Println(leftPad("2", 2, "."))fmt.Println(leftPad("3", 3, "."))fmt.Println(leftPad("4", 4, "."))fmt.Println(leftPad("5", 5, "."))fmt.Println(leftPad("hello", 7, "."))fmt.Println(leftPad("foo", 6, "."))fmt.Println(leftPad("foo", 3, "."))fmt.Println(leftPad("foobar", 3, "."))fmt.Println(leftPad("foo", 6, "?"))}
to save progress
LeftPad in C++
LeftPad in Perl
to save progress