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;
      };
      
      Typescript language logo

      Find lowest sorting order

      Codiga's TypeScript Recipes

      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

        Codiga - All rights reserved 2022.