X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Futils%2FUtils.ts;h=48d0587cbce16e9db798c48877795325e8088eff;hb=ec4a242aa5f1a9d4201d0ec9988f9dd931978589;hp=ff41faf8a674540a8b512ac8664cb61e98bfc6ec;hpb=b5c1950952ab35ca87efc29816010737d0cc159e;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index ff41faf8..48d0587c 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -262,11 +262,12 @@ export const insertAt = (str: string, subStr: string, pos: number): string => * Computes the retry delay in milliseconds using an exponential backoff algorithm. * * @param retryNumber - the number of retries that have already been attempted + * @param maxDelayRatio - the maximum ratio of the delay that can be randomized * @returns delay in milliseconds */ export const exponentialDelay = (retryNumber = 0, maxDelayRatio = 0.2): number => { const delay = Math.pow(2, retryNumber) * 100; - const randomSum = delay * maxDelayRatio * secureRandom(); // 0-20% of the delay + const randomSum = delay * maxDelayRatio * secureRandom(); // 0-(maxDelayRatio*100)% of the delay return delay + randomSum; }; @@ -354,3 +355,12 @@ export const getWebSocketCloseEventStatusString = (code: number): string => { } return '(Unknown)'; }; + +export const isArraySorted = (array: T[], compareFn: (a: T, b: T) => number): boolean => { + for (let index = 0; index < array.length - 1; ++index) { + if (compareFn(array[index], array[index + 1]) > 0) { + return false; + } + } + return true; +};