Problem 70. Alphabetize by last name
Given a list of names in a cell array, sort the list by the last name. So if
list = {'Barney Google','Snuffy Smith','Dagwood Bumstead'};
then the output is
alpha_list = {'Dagwood Bumstead','Barney Google','Snuffy Smith'}
Solution Stats
Problem Comments
-
8 Comments
Be careful with output format...
if length(alpha_list) > 5
alpha_list = alpha_list';
end
The 'Cleve Moler' name has an extra space in the assert list of alpha_names, which was causing a failed solution in Test Case 2. After cludging a solution to match that space, other solutions I tested were apparently not rejected for the same solution I achieved.
@Brent the extra space is be immaterial: it's outside the string. The problem with your earlier non-scoring solutions is the "F." in "John F. Kennedy", which your solutions mistakenly removed
Solution Comments
Show commentsProblem Recent Solvers2286
Suggested Problems
-
Create a cell array out of a struct
2084 Solvers
-
Back to basics 23 - Triangular matrix
1035 Solvers
-
487 Solvers
-
Find a subset that divides the vector into equal halves
391 Solvers
-
Split a string into chunks of specified length
1879 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!