If given an array similar to this one:
input = [
"1.1",
"1.c",
"1.b",
"1",
"D",
"b",
"4",
"2.1.2",
"5.1",
"3",
"2.a.1"
]
What is the best approach to sorting it in order to achieve the following result:
sorted = [
"1",
"1.1",
"1.b",
"1.c",
"b",
"2.a.1",
"2.1.2",
"3",
"4",
"D",
"5.1"
]
In the sorting process, consider:
'a' or 'A' should be treated as 1,
'b' or 'B' should be treated as 2,
and so forth.
The array only contains numbers and letters, no symbols.
I have attempted the following code:
input = ["1", "1.1", "1.b", "1.c", "b", "2.a.1", "2.1.2", "3", "4", "D", "5.1"]
console.log(input.sort((a, b) => a.localeCompare(b)));
This code did not produce the desired outcome. I would appreciate any suggestions or assistance with this issue. Thank you!