I have a list of strings present in the below json format and I need to verify if the displayedString in the outer array is in the sorted order with a slight modification to the sorting logic.
{
"outer": [
{ "inner" : { "displayedString" : "The 40 AOI one"}
{ "inner" : { "displayedString" : "50 AOI one"},
{ "inner" : { "displayedString" : "The ABI one"}
{ "inner" : { "displayedString" : "AOI one"},
{ "inner" : { "displayedString" : "BOI one"},
]
}
The sorting logic has to be 0-9 < A-Z i.e, numbers take priority over the alphabets and also if the displayedString contains "The" as the first word, I need to remove/ignore it and continue with my sorting logic.
For example, in the above "The 40 AOI one" is prior to "50 AOI one" since "The" is removed and 4<5. similarly with "The ABI one" and "AOI one".
How can I verify the json input follows the logic provided?
2
Answers
Sort a copy of your array and compare with original.
While sorting remove
The
prefix with/^thes+/i
regular expression and adjust the collator options to your needs.Create a copy of your list, define a custom sorting function to sort the list of strings based on the given criteria. Finally, you can compare the original list with the sorted list to check if they match.