Description

Solutions

Julia

using Pipe
using Test


reverse_long_word(w::AbstractString)::String = length(w) < 5 ? w : reverse(w)
#> reverse_long_word (generic function with 1 method)
@test reverse_long_word("Hey") == "Hey"
#> Test Passed
#>   Expression: reverse_long_word("Hey") == "Hey"
#>    Evaluated: "Hey" == "Hey"
@test reverse_long_word("fellow") == "wollef"
#> Test Passed
#>   Expression: reverse_long_word("fellow") == "wollef"
#>    Evaluated: "wollef" == "wollef"


"""
翻转一个字符串中较长的单词   
"""
#> "翻转一个字符串中较长的单词   \n"
function spinwords(s::String)::String
    @pipe s |> split .|> reverse_long_word |> join(_, " ")
end
#> spinwords (generic function with 1 method)

@testset "spin words" begin
    @test spinwords("Hey fellow warriors") == "Hey wollef sroirraw"
end
#> Test Summary: | Pass  Total
#> spin words    |    1      1
#> Test.DefaultTestSet("spin words", Any[], 1, false, false)