Cody

Problem 171. Reverse the Words (not letters) of a String

Solution 3676573

Submitted on 16 Nov 2020 by Shi Ke Ong
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = 'Will the ecological jail rule outside the tear'; y_correct = 'tear the outside rule jail ecological the Will'; assert(isequal(reverseWords(x),y_correct))

s3 = [] s3 = "tear" s3 = 1×2 string array "tear" "the" s3 = 1×3 string array "tear" "the" "outside" s3 = 1×4 string array "tear" "the" "outside" "rule" s3 = 1×5 string array "tear" "the" "outside" "rule" "jail" s3 = 1×6 string array "tear" "the" "outside" "rule" "jail" "ecological" s3 = 1×7 string array "tear" "the" "outside" "rule" "jail" "ecological" "the" s3 = 1×8 string array "tear" "the" "outside" "rule" "jail" "ecological" "the" "Will" s2 = "tear the outside rule jail ecological the Will"

2   Pass
x = 'That computer programmer kept the room warm'; y_correct = 'warm room the kept programmer computer That'; assert(isequal(reverseWords(x),y_correct))

s3 = [] s3 = "warm" s3 = 1×2 string array "warm" "room" s3 = 1×3 string array "warm" "room" "the" s3 = 1×4 string array "warm" "room" "the" "kept" s3 = 1×5 string array "warm" "room" "the" "kept" "programmer" s3 = 1×6 string array "warm" "room" "the" "kept" "programmer" "computer" s3 = 1×7 string array "warm" "room" "the" "kept" "programmer" "computer" "That" s2 = "warm room the kept programmer computer That"

3   Pass
x = 'trivial'; y_correct = 'trivial'; assert(isequal(reverseWords(x),y_correct))

s3 = [] s3 = "trivial" s2 = "trivial"

Suggested Problems

More from this Author56

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!