Cody

Problem 70. Alphabetize by last name

Solution 1437280

Submitted on 9 Feb 2018 by Steffen Zelzer
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

alpha_list = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Snuffy Smith'} splitList = 3×2 cell array {'Barney' } {'Google' } {'Snuffy' } {'Smith' } {'Dagwood'} {'Bumstead'} idx = 3 1 2 alpha_list = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Snuffy Smith'}

2   Pass
list = {'Harry Truman' 'Dwight Eisenhower' 'John F. Kennedy' 'Lyndon Johnson' 'Richard Nixon' 'Gerald Ford' 'Cleve Moler' 'Ronald Reagan' 'George Bush' 'Bill Clinton' 'George Bush' 'Barack Obama'}; alpha_list = {'George Bush' 'George Bush' 'Bill Clinton' 'Dwight Eisenhower' 'Gerald Ford' 'Lyndon Johnson' 'John F. Kennedy' 'Cleve Moler' 'Richard Nixon' 'Barack Obama' 'Ronald Reagan' 'Harry Truman'} assert(isequal(alphabetize(list),alpha_list))

alpha_list = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Richard Nixon' } {'Barack Obama' } {'Ronald Reagan' } {'Harry Truman' } splitList = 12×2 cell array {'Harry' } {'Truman' } {'Dwight' } {'Eisenhower'} {'John' } {'Kennedy' } {'Lyndon' } {'Johnson' } {'Richard'} {'Nixon' } {'Gerald' } {'Ford' } {'Cleve' } {'Moler' } {'Ronald' } {'Reagan' } {'George' } {'Bush' } {'Bill' } {'Clinton' } {'George' } {'Bush' } {'Barack' } {'Obama' } idx = 9 11 10 2 6 4 3 7 5 12 8 1 alpha_list = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Richard Nixon' } {'Barack Obama' } {'Ronald Reagan' } {'Harry Truman' }

Community Treasure Hunt

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

Start Hunting!