I am attempting to achieve the following.
strs = ["one", "two"];
let sorted_str = strs.map((s) => [s.sort(), s]);
Basically, my goal is to create a new array of arrays where each nested array consists of the sorted string from the original array and the original string itself.
Despite my efforts, it seems like the .sort()
method is not working as intended in this context.
I even tried converting it explicitly to a String:
let sorted_str = strs.map((s) => [s.toString().sort(), s]);
In an attempt to ensure that it has access to the sort()
method. Unfortunately, I received the error message:
TypeError: s.toString(...).sort is not a function
.
If anyone knows how to make this work or has a simple workaround, any assistance will be greatly appreciated.