Skip to content

gp187/algos-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Algorithms

WIP

** this is a work in progress. Stuff will change, but you can already use it and chat with me **

  • To extend your native Array object with some of the optimized functions, add this as the first line of your index.ts file
    declare global {
        interface Array<T> {
            /**
             * Check if all the variables in the array are truthy
             * @returns {boolean}
             */
            isAllTrue(): boolean;
            /**
             * Sort with correct ordering
             */
            sort(compareFn?: (a: T, b: T) => number): this;
            /**
             * Sort array by key
             */
            sortBy(param: string): this;
            /**
             * Bubble sort
             */
            bubbleSort(): number[];
            /**
             * Quick sort
             */
            quickSort(): number[];
            /**
             * Insert sort
             */
            insertionSort(): number[];
            /**
             * Merge sort algo
             */
            mergeSort(): number[];
            /**
             * Binary search
             */
            binarySearch(element: number, start: number, end: number): number
            /**
             * Find repeated item
             */
            firstRepeatedItem<T>(): T;
        }
    }