From 08dab3545a7105e8a59f4e424e01925250a5fb10 Mon Sep 17 00:00:00 2001 From: Subhajit Sahu Date: Mon, 8 May 2023 01:37:20 +0530 Subject: [PATCH] :bug: chore: rearrange code --- package-lock.json | 4 +- package.json | 2 +- src/index.ts | 98 +++++++++++++++++++++++++---------------------- wiki | 2 +- 4 files changed, 56 insertions(+), 50 deletions(-) diff --git a/package-lock.json b/package-lock.json index 709bccd75..1779557fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "extra-array", - "version": "4.0.2", + "version": "4.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "extra-array", - "version": "4.0.2", + "version": "4.0.3", "license": "MIT", "devDependencies": { "@rollup/plugin-commonjs": "^24.1.0", diff --git a/package.json b/package.json index 0260fc9dc..51019955e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "extra-array", - "version": "4.0.2", + "version": "4.0.3", "description": "An array is a collection of values, stored contiguously.", "main": "index.js", "module": "index.mjs", diff --git a/src/index.ts b/src/index.ts index 9b79fb9ca..66fa56898 100644 --- a/src/index.ts +++ b/src/index.ts @@ -130,28 +130,6 @@ function toSet(x: T[], fm: MapFunction | null=null): Set { // #region GENERATE // ---------------- -/** - * Convert an iterable to array. - * @param x an iterable - * @returns x as array - */ -export function fromIterable(x: Iterable): T[] { - return [...x]; -} -export {fromIterable as from}; - - -/** - * Convert an iterable to array! - * @param x an iterable (updatable if array!) - * @returns x as array - */ -export function fromIterable$(x: Iterable): T[] { - return Array.isArray(x)? x : [...x]; -} -export {fromIterable$ as from$}; - - /** * Generate array from given number range. * @param v start number @@ -197,6 +175,28 @@ export function fromApplication(fm: MapFunction, v: T, n: number): T[] return a; } export {fromApplication as fromApply}; + + +/** + * Convert an iterable to array. + * @param x an iterable + * @returns x as array + */ +export function fromIterable(x: Iterable): T[] { + return [...x]; +} +export {fromIterable as from}; + + +/** + * Convert an iterable to array! + * @param x an iterable (updatable if array!) + * @returns x as array + */ +export function fromIterable$(x: Iterable): T[] { + return Array.isArray(x)? x : [...x]; +} +export {fromIterable$ as from$}; // #endregion @@ -242,18 +242,6 @@ export function is(v: any): v is any[] { } -/** - * Examine if array is sorted. - * @param x an array - * @param fc compare function (a, b) - * @param fm map function (v, i, x) - * @returns x is sorted? - */ -export function isSorted(x: T[], fc: CompareFunction | null=null, fm: MapFunction | null=null): boolean { - return searchUnsortedValue(x, fc, fm) === -1; -} - - /** * Obtain all indices. * @param x an array @@ -317,8 +305,8 @@ export function ientries(x: T[]): IEntries { -// #region LENGTH -// -------------- +// #region INDEX +// ------------- /** * Get zero-based index for an element in array. @@ -345,6 +333,22 @@ export function indexRange(x: T[], i: number=0, I: number=x.length): [number, var I = I>=0? Math.min(I, X) : Math.max(X+I, 0); return [i, Math.max(i, I)]; } +// #endregion + + + + +// #region LENGTH +// -------------- + +/** + * Check if an array is empty. + * @param x an array + * @returns |x| = 0? + */ +export function isEmpty(x: T[]): boolean { + return x.length===0; +} /** @@ -361,16 +365,6 @@ export function length(x: T[], i: number=0, I: number=x.length): number { export {length as size}; -/** - * Check if an array is empty. - * @param x an array - * @returns |x| = 0? - */ -export function isEmpty(x: T[]): boolean { - return x.length===0; -} - - /** * Resize an array to given length! * @param x an array @@ -3192,6 +3186,18 @@ export function cartesianProduct(xs: T[][], fm: MapFunction // #region SORT // ------------ +/** + * Examine if array is sorted. + * @param x an array + * @param fc compare function (a, b) + * @param fm map function (v, i, x) + * @returns x is sorted? + */ +export function isSorted(x: T[], fc: CompareFunction | null=null, fm: MapFunction | null=null): boolean { + return searchUnsortedValue(x, fc, fm) === -1; +} + + /** * Arrange values in order. * @param x an array diff --git a/wiki b/wiki index 4de4f82e8..0310f98b7 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 4de4f82e8d0b747148fb76e0d6b69dde850812c1 +Subproject commit 0310f98b7a74416d023549e049e5eb9891b6e011