How to resolve the algorithm Phrase reversals step by step in the Dyalect programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Phrase reversals step by step in the Dyalect programming language
Table of Contents
Problem Statement
Given a string of space separated words containing the following phrase:
Show your output here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Phrase reversals step by step in the Dyalect programming language
Source code in the dyalect programming language
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.Length()-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.Length()-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))")
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the Fermat programming language
You may also check:How to resolve the algorithm 2048 step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Multiple regression step by step in the J programming language
You may also check:How to resolve the algorithm Apply a callback to an array step by step in the C# programming language
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Nemerle programming language