Cody

Problem 44. Trimming Spaces

Solution 734698

Submitted on 14 Sep 2015 by toofan
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
%% a = 'no extra spaces'; b = 'no extra spaces'; assert(isequal(b,removeSpaces(a)))

a = no extra spaces c = Columns 1 through 16 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 Columns 17 through 19 0 1 1 d = 0 1 ic = 3 1 ig = 2 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 2 e = 19 ig = 2 1 2 2 1 3 1 4 2 5 1 6 1 7 1 8 1 9 1 10 2 11 1 12 1 13 1 14 1 15 1 16 1 17 2 18 2 19 f = 3 4 6 7 8 9 10 12 13 14 15 16 17 startIndex = 3 endIndex = 17 b = no extra spaces

2   Pass
%% a = ' lots of space in front'; b = 'lots of space in front'; assert(isequal(b,removeSpaces(a)))

a = lots of space in front c = Columns 1 through 16 1 1 1 1 1 1 1 1 0 0 0 0 1 0 0 1 Columns 17 through 32 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 d = 0 1 ic = 9 1 ig = 2 2 2 2 2 2 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 2 2 e = 32 ig = 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 1 9 1 10 1 11 1 12 2 13 1 14 1 15 2 16 1 17 1 18 1 19 1 20 1 21 2 22 1 23 1 24 2 25 1 26 1 27 1 28 1 29 1 30 2 31 2 32 f = 9 10 11 12 14 15 17 18 19 20 21 23 24 26 27 28 29 30 startIndex = 9 endIndex = 30 b = lots of space in front

3   Pass
%% a = 'lots of space in back '; b = 'lots of space in back'; assert(isequal(b,removeSpaces(a)))

a = lots of space in back c = Columns 1 through 16 1 1 0 0 0 0 1 0 0 1 0 0 0 0 0 1 Columns 17 through 31 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 d = 0 1 ic = 3 1 ig = 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 2 2 2 2 2 2 2 2 e = 31 ig = 2 1 2 2 1 3 1 4 1 5 1 6 2 7 1 8 1 9 2 10 1 11 1 12 1 13 1 14 1 15 2 16 1 17 1 18 2 19 1 20 1 21 1 22 1 23 2 24 2 25 2 26 2 27 2 28 2 29 2 30 2 31 f = 3 4 5 6 8 9 11 12 13 14 15 17 18 20 21 22 23 startIndex = 3 endIndex = 23 b = lots of space in back

4   Pass
%% a = ' space on both sides '; b = 'space on both sides'; assert(isequal(b,removeSpaces(a)))

a = space on both sides c = Columns 1 through 16 1 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 Columns 17 through 32 1 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 Column 33 1 d = 0 1 ic = 9 1 ig = 2 2 2 2 2 2 2 2 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 2 2 2 e = 33 ig = 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 1 9 1 10 1 11 1 12 1 13 2 14 1 15 1 16 2 17 1 18 1 19 1 20 1 21 2 22 1 23 1 24 1 25 1 26 1 27 2 28 2 29 2 30 2 31 2 32 2 33 f = 9 10 11 12 13 15 16 18 19 20 21 23 24 25 26 27 startIndex = 9 endIndex = 27 b = space on both sides

5   Pass
%% a = sprintf('\ttab in front, space at end '); b = sprintf('\ttab in front, space at end'); assert(isequal(b,removeSpaces(a)))

a = tab in front, space at end c = Columns 1 through 16 1 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 Columns 17 through 32 1 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 Columns 33 through 35 1 1 1 d = 0 1 ic = 3 1 ig = 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 2 2 e = 35 ig = 2 1 2 2 1 3 1 4 1 5 1 6 2 7 1 8 1 9 2 10 1 11 1 12 1 13 1 14 1 15 1 16 2 17 1 18 1 19 1 20 1 21 1 22 2 23 1 24 1 25 2 26 1 27 1 28 1 29 2 30 2 31 2 32 2 33 2 34 2 35 f = 3 4 5 6 8 9 11 12 13 14 15 16 18 19 20 21 22 24 25 27 28 29 startIndex = 3 endIndex = 29 b = tab in front, space at end

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!