I need help finding a way to create an ordered array of indexes from another array in TypeScript.
Let me provide some examples: imagine a function that takes an array of any length and returns another array with the indexes of the elements in ascending order:
- Example 1: Input=(5.3, 2.4, 4.5, 6.2) > Output=(1,2,0,3).
- Example 2: Input=(10, 11, 5, 34, 3, 7, 17) > Output=(4,2,5,0,1,6,3).
I am unable to use array.sort()
as it would alter the original array.
I am struggling with this problem as my experience with JS and TS is limited (I am a Delphi programmer who is a bit rusty).
Any insights or advice would be greatly appreciated. Thank you in advance.