Phrase reversals: Difference between revisions

Content added Content deleted
m (Added Dyalect lang)
Line 721: Line 721:
attesor edoc esarhp lasrever
attesor edoc esarhp lasrever
reversal phrase code rosetta</pre>
reversal phrase code rosetta</pre>

=={{header|Dyalect}}==
<lang dyalect>let str = "rosetta code phrase reversal"

//or you can use a built-in method String.reverse
func reverse(str) {
let xs = []
for i in (str.len()-1)^-1..0 {
xs.add(str[i])
}
String.concat(values: xs)
}

func reverseByWord(str) {
let words = str.split(" ")
let xs = []
for w in words {
xs.add(reverse(w))
xs.add(" ")
}
String.concat(values: xs)
}

func reverseWords(str) {
let words = str.split(" ")
let xs = []
for i in (words.len()-1)^-1..0 {
xs.add(words[i])
xs.add(" ")
}
String.concat(values: xs)
}

print("1. \(reverse(str))")
print("2. \(reverseByWord(str))")
print("3. \(reverseWords(str))")</lang>


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==