6 kyu

Sorting Book Titles: Ignoring Articles

Description:

When sorting lists of book titles alphabetically, articles (the, an, or a) in the beginning of the title should be ignored, and moved to the end.

For example, given a list that contains A Petition to Magic and Heritage of Deceit, Heritage of Deceit should be sorted before A Petition to Magic.

The remainder of the title should be sorted as if the article was appended to the end of the title.

For example, A Petition to Magic becomes Petition to Magic, A for purposes of sorting, and The Great Gatsby becomes Great Gatsby, The.

Write a method that receives a list of book titles as strings, and returns a new, sorted list, which follows the above rules.

You should not modify the original title. It should be returned as-is in the resulting list.

If null is passed to the method, it should return null. If an empty list is passed, the method should return an empty list.

Note: only exclude articles if they appear in the beginning of the title. For example, if a title happens to include the word The in the middle, that word should not be excluded.

Also, do not exclude articles if the entire title is an article (for example, a book titled simply The should remain The for purposes of sorting).

Lists
Strings
Sorting
Algorithms

More By Author:

Check out these other kata created by GrahamD

Stats:

CreatedMay 3, 2017
PublishedMay 8, 2017
Warriors Trained251
Total Skips1
Total Code Submissions1020
Total Times Completed95
C# Completions95
Total Stars8
% of votes with a positive feedback rating88% of 45
Total "Very Satisfied" Votes36
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes2
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • GrahamD Avatar
  • smile67 Avatar
  • hobovsky Avatar
Ad