0
1
GGGiovanny Gongora
Finds the lowest index at which a value should be inserted into an array in order to maintain its sorting order.
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;
};