Created
November 18, 2023 00:35
-
-
Save harmoniemand/4af020ae7f8a6ea6a229fc3eb246a1fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wordrevert | |
func ReadUntil(text []rune, search rune) []rune { | |
read := []rune{} | |
for _, char := range text { | |
if char == search { | |
break | |
} | |
read = append(read, char) | |
} | |
return read | |
} | |
func Trim(text []rune) []rune { | |
trimmed := []rune{} | |
for _, char := range text { | |
if char != ' ' { | |
trimmed = append(trimmed, char) | |
} | |
} | |
return trimmed | |
} | |
func RevertWords(text []rune) []rune { | |
reverted := []rune{} | |
for len(text) > 0 { | |
word := ReadUntil(text, ' ') | |
reverted = append(word, reverted...) | |
reverted = append([]rune(" "), reverted...) | |
text = Trim(text[len(word):]) | |
} | |
return reverted[1:] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment