For your sample data, the OPs specifications, should lead to an ordering of:
copy carpet soap error prawn emblem cabin echo pail engine reptile esk +imo skunk
Not:
carpet error prawn reptile emblem engine echo eskimo copy soap cabin p +ail skunk
Consider the OPs 3-part specification and the following:
orig pre-r sort-r pre-e sort-e pre-o sort-O + final cabin cabin copy + copy prawn prawn carpet + carpet pail pail soap + soap error error error + error reptile reptile prawn + prawn engine engine emblem + emblem copy copy cabin + cabin echo echo echo + echo soap soap pail + pail eskimo eskimo engine + engine carpet carpet reptile + reptile emblem emblem eskimo + eskimo skunk skunk skunk + skunk
The problem with your algorithm is, that is doesn't exclude those items that match the first criteria, from being considered by the second criteria, if the also match it; but the OPs specifications (emphasis added):
all the strings inside the array that contain an “r” and sort those in ascending alphabetical order. For the elements that are left, find the ones that start with an “e” and sort those by ascii value of their third character. And for the ones that are left reverse sort by their last letter alphabetically.
Your algorithm does not exclude items that contain an 'r' from being considered when processing items that start with an 'e'. Eg. 'error'.
Nor does it exclude items that contain an 'r', or start with an 'e', from being processed when reverse sorting "the ones that are left".
In reply to Re^2: How to perform different sorts on multiple sections of items in the same array
by BrowserUk
in thread How to perform different sorts on multiple sections of items in the same array
by estreb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |