Strings
-
Implement a function
func trimLeftSpace(s string) stringthat returns a slice of the stringswith all leading space characters (https://en.wikipedia.org/wiki/Space_(punctuation)) removed:Example:
trimLeftSpace("gopher") -> "gopher" trimLeftSpace(" go goper") -> "go gopher" -
Implement a function
func trimRightSpace(s string) stringthat returns a slice of the stringswith all trailing space characters (https://en.wikipedia.org/wiki/Space_(punctuation)) removed:Example:
trimRightSpace("gopher") -> "gopher" trimRightSpace("go goper ") -> "go gopher" -
Implement a function
func trimSpace(s string) stringthat returns a slice of the stringswith all leading and trailing space characters (https://en.wikipedia.org/wiki/Space_(punctuation)) removed:Example:
trimSpace(" we are surrounded ") -> "we are surrounded" -
Implement a function
func index(s, subs string) intthat returns the index of the left-most instance of substringsubsins, or -1 if substringsubsdoes not present ins:Example:
index("foo", "oo") -> 1 index("foo", "") -> 0 index("foo", "bar") -> -1 -
Implement a function
func rightIndex(s, subs string) intthat returns the index of the right-most instance of substringsubsins, or -1 if substringsubsdoes not present ins:Example:
rightIndex("foofoo", "oo") -> 4 rightIndex("foo", "") -> 3 rightIndex("foo", "bar") -> -1 -
Implement a function
func indices(s, subs string) []intthat returns all indices of substringsubsinswith an overlap (it means that “oo” in “ooo” will be matched twice - at positions 0 and 1):Example:
rightIndex("fooofooo", "oo") -> [1 2 5 6] rightIndex("foo", "") -> [] rightIndex("foo", "bar") -> [] -
Implement a function
func isNumber(s string) boolthat returns true ifsconsists of digits [0..9] only:Example:
isNumber("") -> false isNumber("abc") -> false isNumber("12ab") -> false isNumber("0") -> true isNumber("123") -> true -
Implement a function
func itoa(n int) stringthat returns a string representation (base 10) of a given integer:Example:
itoa(0) -> "0" itoa(123) -> "123" itoa(-123) -> "-123" -
Implement a function
func normalizeNumber(n string) (norm string, num bool)that removes trailing space characters and leading ‘0’ and space characters ifnis a number (as returned byisNumber()function). Ifnis not a number, thenisNumberreturn value should be set to false:Example:
normalizeNumber("") -> ["" false] normalizeNumber(" ") -> ["" false] normalizeNumber(" abc ") -> ["" false] normalizeNumber(" 00123") -> ["" true] -
Implement a function
func insertAt(s, subs string, i int) stringthat inserts a substring into a string after an index provided. If the initial string is too short, space character should be used to fill the necessary space. Negative index is valid and means that the insertion index starts from the end of the string in negative direction.Example:
insertAt("bar", "foo", 0) -> "foobar" insertAt("bar", "foo", 1) -> "bfooar" insertAt("bar", "foo", 3) -> "barfoo" insertAt("bar", "foo", -1) -> "barfoo" insertAt("bar", "foo", 4) -> "bar foo" insertAt("", "foo", 4) -> " foo"