Cody

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

Solution 1188184

Submitted on 14 May 2017 by Said BOUREZG
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))

k = cell 'Will' ans = 1×8 cell array 'tear' 'the' 'ecological' 'jail' 'rule' 'outside' 'the' 'tear' ans = 1×8 cell array 'tear' 'the' 'ecological' 'jail' 'rule' 'outside' 'the' 'Will' k = cell 'the' ans = 1×8 cell array 'tear' 'the' 'ecological' 'jail' 'rule' 'outside' 'the' 'Will' ans = 1×8 cell array 'tear' 'the' 'ecological' 'jail' 'rule' 'outside' 'the' 'Will' k = cell 'ecological' ans = 1×8 cell array 'tear' 'the' 'outside' 'jail' 'rule' 'outside' 'the' 'Will' ans = 1×8 cell array 'tear' 'the' 'outside' 'jail' 'rule' 'ecological' 'the' 'Will' k = cell 'jail' ans = 1×8 cell array 'tear' 'the' 'outside' 'rule' 'rule' 'ecological' 'the' 'Will' ans = 1×8 cell array 'tear' 'the' 'outside' 'rule' 'jail' 'ecological' 'the' 'Will' ans = '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))

k = cell 'That' ans = 1×7 cell array 'warm' 'computer' 'programmer' 'kept' 'the' 'room' 'warm' ans = 1×7 cell array 'warm' 'computer' 'programmer' 'kept' 'the' 'room' 'That' k = cell 'computer' ans = 1×7 cell array 'warm' 'room' 'programmer' 'kept' 'the' 'room' 'That' ans = 1×7 cell array 'warm' 'room' 'programmer' 'kept' 'the' 'computer' 'That' k = cell 'programmer' ans = 1×7 cell array 'warm' 'room' 'the' 'kept' 'the' 'computer' 'That' ans = 1×7 cell array 'warm' 'room' 'the' 'kept' 'programmer' 'computer' 'That' ans = 'warm room the kept programmer computer That'

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

ans = '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!