phrase = "rosetta code phrase reversal" // general sequence reversal function reverse = function(seq) out = [] for i in range(seq.len-1, 0) out.push seq[i] end for if seq isa string then return out.join("") return out end function // 1. Reverse the characters of the string. print reverse(phrase) // 2. Reverse the characters of each individual word in the string, maintaining original word order within the string. words = phrase.split for i in words.indexes words[i] = reverse(words[i]) end for print words.join // 3. Reverse the order of each word of the string, maintaining the order of characters in each word. print reverse(phrase.split).join