GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — javascript-datastructures-algorithms/src/ts/util.ts at main · rontian/javascript-datastructures-algorithms Expand file tree/ Copy pathutil.tsMore file actions 60 lines (48 loc) · 1.52 KB / Copy pathutil.tsFile metadata and controls60 lines (48 loc) · 1.52 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 export type ICompareFunction<T> = (a: T, b: T) => number; export type IEqualsFunction<T> = (a: T, b: T) => boolean; export type IDiffFunction<T> = (a: T, b: T) => number; export const DOES_NOT_EXIST = -1; export enum Compare { LESS_THAN = -1, BIGGER_THAN = 1, EQUALS = 0 } export function lesserEquals<T>(a: T, b: T, compareFn: ICompareFunction<T>) { const comp = compareFn(a, b); return comp === Compare.LESS_THAN || comp === Compare.EQUALS; } export function biggerEquals<T>(a: T, b: T, compareFn: ICompareFunction<T>) { const comp = compareFn(a, b); return comp === Compare.BIGGER_THAN || comp === Compare.EQUALS; } export function defaultCompare<T>(a: T, b: T): number { if (a === b) { return Compare.EQUALS; } return a < b ? Compare.LESS_THAN : Compare.BIGGER_THAN; } export function defaultEquals<T>(a: T, b: T): boolean { return a === b; } export function defaultToString(item: any): string { if (item === null) { return 'NULL'; } else if (item === undefined) { return 'UNDEFINED'; } else if (typeof item === 'string' || item instanceof String) { return `${item}`; } return item.toString(); } export function swap(array: any[], a: number, b: number) { /* const temp = array[a]; array[a] = array[b]; array[b] = temp; */ [array[a], array[b]] = [array[b], array[a]]; } export function reverseCompare<T>(compareFn: ICompareFunction<T>): ICompareFunction<T> { return (a, b) => compareFn(b, a); } export function defaultDiff<T>(a: T, b: T): number { return Number(a) - Number(b); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |