UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

68 lines (67 loc) 2.39 kB
"use strict"; // import GridBase from '../../../Grid0.x/lib/Common/Base.js'; // import GridModel from '../../../Grid0.x/lib/Common/data/Model.js'; // // //--------------------------------------------------------------------------------------- // declare class MyBase { // constructor(...args : any[]) // // construct(...args : any[]) // } // // declare class MyModel extends MyBase { // static fields : any[] // // id : ModelId // internalId : ModelInternalId // // parent // // traverse (fn : (model : Model) => any, skipSelf? : boolean) // } // // export const Base : Constructable<MyBase> = GridBase // export const Model : Constructable<MyModel> = GridModel // // export type Base = MyBase // export type Model = MyModel Object.defineProperty(exports, "__esModule", { value: true }); //--------------------------------------------------------------------------------------- // One should use Base as a base class, instead of Object // this is because, when compiled to ES3 (which we use for NodeJS / IE11 compatibility), Object is called as a // super constructor and returned value from it is used as an instance object // that instance object will be missing prototype inheritance var Base = /** @class */ (function () { function Base() { } return Base; }()); exports.Base = Base; //--------------------------------------------------------------------------------------- exports.binarySearch = function (value, array, comparator) { if (comparator === void 0) { comparator = (function (a, b) { return a - b; }); } var left = 0; var right = array.length; while (left < right) { // | 0 to make it integer, faster according to: https://jsperf.com/or-vs-floor/2 var mid = (left + right) / 2 | 0; var compare = comparator(value, array[mid]); if (compare === 0) return { found: true, index: mid }; else if (compare < 0) right = mid; else left = mid + 1; } return { found: false, index: right }; }; //--------------------------------------------------------------------------------------- exports.stripDuplicates = function (array) { var seen = new Map(); return array.filter(function (el) { if (seen.has(el)) return false; seen.set(el, true); return true; }); };