const sortedIndex = (arr: Array<number>, n: number) => {
const isDescending: boolean = arr[0] > arr[arr.length - 1];
const index: number = arr.findIndex(el => (isDescending ? n >= el : n <= el));
return index === -1 ? arr.length : index;
};
Find lowest sorting order
Finds the lowest index at which a value should be inserted into an array in order to maintain its sorting order.
0 Comments
Add Comment
Log in to add a comment