New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@amaui/algorithms

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amaui/algorithms - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

bubble-sort.d.ts

@@ -1,1 +0,1 @@

export default function bubbleSort<T = number>(value: Array<T>): Array<T>;
export default function bubbleSort<T = number>(value: Array<T>, ascending?: boolean): Array<T>;

@@ -7,3 +7,3 @@ "use strict";

// Complexity: O(n ^ 2)
function bubbleSort(value) {
function bubbleSort(value, ascending = true) {
const length = value.length;

@@ -14,3 +14,3 @@ let swapped = true;

for (let i = 0; i < length; i++) {
if (value[i] > value[i + 1]) {
if (ascending ? value[i] > value[i + 1] : value[i] < value[i + 1]) {
const item = value[i];

@@ -17,0 +17,0 @@ value[i] = value[i + 1];

@@ -7,2 +7,3 @@ // While loop runs, and in each loop, the entire array is looped and for every i,

export default function bubbleSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = value.length;

@@ -13,3 +14,3 @@ let swapped = true;

for (let i = 0; i < length; i++) {
if (value[i] > value[i + 1]) {
if (ascending ? value[i] > value[i + 1] : value[i] < value[i + 1]) {
const item = value[i];

@@ -16,0 +17,0 @@ value[i] = value[i + 1];

@@ -1,2 +0,2 @@

/** @license AmauiAlgorithms v1.0.0
/** @license AmauiAlgorithms v1.0.1
*

@@ -3,0 +3,0 @@ * This source code is licensed under the MIT license found in the

@@ -6,2 +6,3 @@ // Array is all the time split between sorted and unsorted part of the array.In every loop first element of unsorted part is compared to sorted part of the array from end to start(of sorted part), and every item from back to start in sorted part of the array that’s larger than first item in unsorted part of the array is swapped with item + 1 next to it.

export default function insertionSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = value.length;

@@ -11,3 +12,3 @@ for (let i = 1; i < length; i++) {

let j = i - 1;
while (j >= 0 && value[j] > item) {
while (j >= 0 && (ascending ? value[j] > item : value[j] < item)) {
value[j + 1] = value[j];

@@ -14,0 +15,0 @@ j--;

// Divides the array down the middle, recursively until last recursted method instance has array of length 1. And then starts merging back all those recursed instances from length of element 1, to the first 2 halves of the array, and merge them, checking left and right half and items in them, and pushing to resulting array items in order from lowest to highest, until recursion is back to the initial array.
// Complexity: O(n ^ 2)
export function mergeSortResolve(array1, array2) {
let ascending = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
const result = [];

@@ -8,3 +9,3 @@ let i = 0;

while (i < array1.length && j < array2.length) {
if (array1[i] < array2[j]) {
if (ascending ? array1[i] < array2[j] : array1[i] > array2[j]) {
result.push(array1[i]);

@@ -28,8 +29,9 @@ i++;

export default function mergeSort(array) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (array.length <= 1) return array;
const length = array.length;
const mid = Math.floor(length / 2);
const left = mergeSort(array.slice(0, mid));
const right = mergeSort(array.slice(mid));
return mergeSortResolve(left, right);
const left = mergeSort(array.slice(0, mid), ascending);
const right = mergeSort(array.slice(mid), ascending);
return mergeSortResolve(left, right, ascending);
}
// Find a pivot item in the array, and go through all values from left to right, and all values less than the pivot value add them to left array, and all values bigger than pivot value, add them to the right array.Recursively now use the quick sort method on left and right arrays, and merge them back together with pivot value being in the middle.
// Complexity: O(n * log n)
export default function quickSort(array) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = array.length;

@@ -15,6 +16,6 @@ if (length <= 1) return array;

while (i < length - 1) {
if (array[i] < pivot) left.push(array[i]);else right.push(array[i]);
if (ascending ? array[i] < pivot : array[i] > pivot) left.push(array[i]);else right.push(array[i]);
i++;
}
return [...quickSort(left), pivot, ...quickSort(right)];
return [...quickSort(left, ascending), pivot, ...quickSort(right, ascending)];
}

@@ -15,2 +15,3 @@ // Including the sign (+,-)

export default function radixSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
let array = value;

@@ -30,3 +31,3 @@ const digits = maxDigits(array);

const index = getDigit(array[j], i);
buckets[index + 1].push(array[j]);
buckets[ascending ? index + 1 : 10 - (index + 1)].push(array[j]);
}

@@ -33,0 +34,0 @@ array = buckets.flatMap(item => item);

@@ -5,12 +5,13 @@ // For every i, an entire i + 1 slice of array is looped to find the min value(smaller than i) within it,

export default function selectionSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = value.length;
for (let i = 0; i < length; i++) {
let min = i;
let minOrMax = i;
for (let j = i + 1; j < length; j++) {
if (value[j] < value[min]) min = j;
if (ascending ? value[j] < value[minOrMax] : value[j] > value[minOrMax]) minOrMax = j;
}
if (min !== i) {
if (minOrMax !== i) {
const item = value[i];
value[i] = value[min];
value[min] = item;
value[i] = value[minOrMax];
value[minOrMax] = item;
}

@@ -17,0 +18,0 @@ }

@@ -1,1 +0,1 @@

export default function insertionSort<T = number>(value: Array<T>): Array<T>;
export default function insertionSort<T = number>(value: Array<T>, ascending?: boolean): Array<T>;

@@ -6,3 +6,3 @@ "use strict";

// Complexity: O(n ^ 2)
function insertionSort(value) {
function insertionSort(value, ascending = true) {
const length = value.length;

@@ -12,3 +12,3 @@ for (let i = 1; i < length; i++) {

let j = i - 1;
while (j >= 0 && value[j] > item) {
while (j >= 0 && (ascending ? value[j] > item : value[j] < item)) {
value[j + 1] = value[j];

@@ -15,0 +15,0 @@ j--;

@@ -1,2 +0,2 @@

export declare function mergeSortResolve<T = number>(array1: Array<T>, array2: Array<T>): Array<T>;
export default function mergeSort<T = number>(array: Array<T>): Array<T>;
export declare function mergeSortResolve<T = number>(array1: Array<T>, array2: Array<T>, ascending?: boolean): Array<T>;
export default function mergeSort<T = number>(array: Array<T>, ascending?: boolean): Array<T>;

@@ -6,3 +6,3 @@ "use strict";

// Complexity: O(n ^ 2)
function mergeSortResolve(array1, array2) {
function mergeSortResolve(array1, array2, ascending = true) {
const result = [];

@@ -12,3 +12,3 @@ let i = 0;

while (i < array1.length && j < array2.length) {
if (array1[i] < array2[j]) {
if (ascending ? array1[i] < array2[j] : array1[i] > array2[j]) {
result.push(array1[i]);

@@ -33,3 +33,3 @@ i++;

exports.mergeSortResolve = mergeSortResolve;
function mergeSort(array) {
function mergeSort(array, ascending = true) {
if (array.length <= 1)

@@ -39,6 +39,6 @@ return array;

const mid = Math.floor(length / 2);
const left = mergeSort(array.slice(0, mid));
const right = mergeSort(array.slice(mid));
return mergeSortResolve(left, right);
const left = mergeSort(array.slice(0, mid), ascending);
const right = mergeSort(array.slice(mid), ascending);
return mergeSortResolve(left, right, ascending);
}
exports.default = mergeSort;
{
"name": "@amaui/algorithms",
"version": "1.0.0",
"version": "1.0.1",
"description": "Algorithms",

@@ -5,0 +5,0 @@ "repository": "https://github.com/amaui-org/amaui-algorithms.git",

@@ -1,1 +0,1 @@

export default function quickSort<T = number>(array: Array<T>): Array<T>;
export default function quickSort<T = number>(array: Array<T>, ascending?: boolean): Array<T>;

@@ -5,3 +5,3 @@ "use strict";

// Complexity: O(n * log n)
function quickSort(array) {
function quickSort(array, ascending = true) {
const length = array.length;

@@ -17,3 +17,3 @@ if (length <= 1)

while (i < length - 1) {
if (array[i] < pivot)
if (ascending ? array[i] < pivot : array[i] > pivot)
left.push(array[i]);

@@ -24,4 +24,4 @@ else

}
return [...quickSort(left), pivot, ...quickSort(right)];
return [...quickSort(left, ascending), pivot, ...quickSort(right, ascending)];
}
exports.default = quickSort;
export declare function maxDigits<T = number>(array: Array<T>): number;
export declare function getDigit(value: number, indexValue: number): number;
export default function radixSort<T = number>(value: Array<T>): Array<T>;
export default function radixSort<T = number>(value: Array<T>, ascending?: boolean): Array<T>;

@@ -18,3 +18,3 @@ "use strict";

// Complexity: O(n)
function radixSort(value) {
function radixSort(value, ascending = true) {
let array = value;

@@ -30,3 +30,3 @@ const digits = maxDigits(array);

const index = getDigit(array[j], i);
buckets[index + 1].push(array[j]);
buckets[ascending ? index + 1 : 10 - (index + 1)].push(array[j]);
}

@@ -33,0 +33,0 @@ array = buckets.flatMap(item => item);

@@ -1,1 +0,1 @@

export default function selectionSort<T = number>(value: Array<T>): Array<T>;
export default function selectionSort<T = number>(value: Array<T>, ascending?: boolean): Array<T>;

@@ -6,14 +6,14 @@ "use strict";

// Complexity: O(n ^ 2)
function selectionSort(value) {
function selectionSort(value, ascending = true) {
const length = value.length;
for (let i = 0; i < length; i++) {
let min = i;
let minOrMax = i;
for (let j = i + 1; j < length; j++) {
if (value[j] < value[min])
min = j;
if (ascending ? value[j] < value[minOrMax] : value[j] > value[minOrMax])
minOrMax = j;
}
if (min !== i) {
if (minOrMax !== i) {
const item = value[i];
value[i] = value[min];
value[min] = item;
value[i] = value[minOrMax];
value[minOrMax] = item;
}

@@ -20,0 +20,0 @@ }

@@ -1,2 +0,2 @@

/** @license AmauiAlgorithms v1.0.0
/** @license AmauiAlgorithms v1.0.1
*

@@ -286,2 +286,3 @@ * This source code is licensed under the MIT license found in the

function bubbleSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = value.length;

@@ -292,3 +293,3 @@ let swapped = true;

for (let i = 0; i < length; i++) {
if (value[i] > value[i + 1]) {
if (ascending ? value[i] > value[i + 1] : value[i] < value[i + 1]) {
const item = value[i];

@@ -308,12 +309,13 @@ value[i] = value[i + 1];

function selectionSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = value.length;
for (let i = 0; i < length; i++) {
let min = i;
let minOrMax = i;
for (let j = i + 1; j < length; j++) {
if (value[j] < value[min]) min = j;
if (ascending ? value[j] < value[minOrMax] : value[j] > value[minOrMax]) minOrMax = j;
}
if (min !== i) {
if (minOrMax !== i) {
const item = value[i];
value[i] = value[min];
value[min] = item;
value[i] = value[minOrMax];
value[minOrMax] = item;
}

@@ -329,2 +331,3 @@ }

function insertionSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = value.length;

@@ -334,3 +337,3 @@ for (let i = 1; i < length; i++) {

let j = i - 1;
while (j >= 0 && value[j] > item) {
while (j >= 0 && (ascending ? value[j] > item : value[j] < item)) {
value[j + 1] = value[j];

@@ -347,2 +350,3 @@ j--;

function mergeSortResolve(array1, array2) {
let ascending = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
const result = [];

@@ -352,3 +356,3 @@ let i = 0;

while (i < array1.length && j < array2.length) {
if (array1[i] < array2[j]) {
if (ascending ? array1[i] < array2[j] : array1[i] > array2[j]) {
result.push(array1[i]);

@@ -372,8 +376,9 @@ i++;

function mergeSort(array) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (array.length <= 1) return array;
const length = array.length;
const mid = Math.floor(length / 2);
const left = mergeSort(array.slice(0, mid));
const right = mergeSort(array.slice(mid));
return mergeSortResolve(left, right);
const left = mergeSort(array.slice(0, mid), ascending);
const right = mergeSort(array.slice(mid), ascending);
return mergeSortResolve(left, right, ascending);
}

@@ -384,2 +389,3 @@

function quickSort(array) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
const length = array.length;

@@ -396,6 +402,6 @@ if (length <= 1) return array;

while (i < length - 1) {
if (array[i] < pivot) left.push(array[i]);else right.push(array[i]);
if (ascending ? array[i] < pivot : array[i] > pivot) left.push(array[i]);else right.push(array[i]);
i++;
}
return [...quickSort(left), pivot, ...quickSort(right)];
return [...quickSort(left, ascending), pivot, ...quickSort(right, ascending)];
}

@@ -417,2 +423,3 @@

function radixSort(value) {
let ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
let array = value;

@@ -432,3 +439,3 @@ const digits = maxDigits(array);

const index = getDigit(array[j], i);
buckets[index + 1].push(array[j]);
buckets[ascending ? index + 1 : 10 - (index + 1)].push(array[j]);
}

@@ -435,0 +442,0 @@ array = buckets.flatMap(item => item);

@@ -1,2 +0,2 @@

/** @license AmauiAlgorithms v1.0.0
/** @license AmauiAlgorithms v1.0.1
*

@@ -6,2 +6,2 @@ * This source code is licensed under the MIT license found in the

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AmauiAlgorithms={})}(this,(function(e){"use strict";const t={};const r={};const n={};const o={};var a="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};const c={},i="undefined"!=typeof window&&void 0!==window.document,u=!(void 0===a||"undefined"==typeof module||!module.exports);function s(e,t){var r;let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const o={...c,...n},{variant:a}=o,f=t&&"object"==typeof t&&Object.getPrototypeOf(t);switch(e){case"string":return"string"==typeof t;case"number":return"number"==typeof t&&!Number.isNaN(t);case"boolean":return"boolean"==typeof t;case"array":return Array.isArray(t);case"object":return"object"==typeof t&&!!t&&t.constructor===Object;case"object-like":return"object"==typeof t&&(null===t||t.constructor!==Object);case"class":return("object"==typeof t||"function"==typeof t)&&(/class/gi.test(String(t))||/class/gi.test(String(null==t?void 0:t.constructor)));case"function":return!!(t&&t instanceof Function);case"async":return!(!s("function",t)||!(i?"AsyncFunction"===t.constructor.name:t()instanceof Promise));case"map":return!(f!==Map.prototype);case"weakmap":return!(f!==WeakMap.prototype);case"set":return!(f!==Set.prototype);case"weakset":return!(f!==WeakSet.prototype);case"promise":return!(f!==Promise.prototype);case"int8array":return!(f!==Int8Array.prototype);case"uint8array":return!(f!==Uint8Array.prototype);case"uint8clampedarray":return!(f!==Uint8ClampedArray.prototype);case"int16array":return!(f!==Int16Array.prototype);case"uint16array":return!(f!==Uint16Array.prototype);case"int32array":return!(f!==Int32Array.prototype);case"uint32array":return!(f!==Uint32Array.prototype);case"float32array":return!(f!==Float32Array.prototype);case"float64array":return!(f!==Float64Array.prototype);case"bigint64array":return!(f!==BigInt64Array.prototype);case"biguint64array":return!(f!==BigUint64Array.prototype);case"typedarray":return s("int8array",t)||s("uint8array",t)||s("uint8clampedarray",t)||s("int16array",t)||s("uint16array",t)||s("int32array",t)||s("uint32array",t)||s("float32array",t)||s("float64array",t)||s("bigint64array",t)||s("biguint64array",t);case"dataview":return!(f!==DataView.prototype);case"arraybuffer":return!(f!==ArrayBuffer.prototype);case"sharedarraybuffer":return"undefined"!=typeof SharedArrayBuffer&&!(f!==SharedArrayBuffer.prototype);case"symbol":return!("symbol"!=typeof t);case"error":return!!(t&&t instanceof Error);case"date":return!!(t&&t instanceof Date);case"regexp":return!!(t&&t instanceof RegExp);case"arguments":return!(!t||"[object Arguments]"!==t.toString());case"null":return null===t;case"undefined":return void 0===t;case"blob":return i&&t instanceof Blob;case"buffer":return!(!u||"function"!=typeof(null==t||null===(r=t.constructor)||void 0===r?void 0:r.isBuffer)||!t.constructor.isBuffer(t));case"element":if(t)switch(a){case void 0:case"html":case"element":return i&&("object"==typeof HTMLElement?t instanceof HTMLElement:t&&"object"==typeof t&&null!==t&&1===t.nodeType&&"string"==typeof t.nodeName);case"node":return i&&("object"==typeof Node?t instanceof Node:t&&"object"==typeof t&&null!==t&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName);case"react":return t.elementType||t.hasOwnProperty("$$typeof");default:return!1}return!1;case"simple":return s("string",t,o)||s("number",t,o)||s("boolean",t,o)||s("undefined",t,o)||s("null",t,o);case"not-array-object":return!s("array",t,o)&&!s("object",t,o);default:return!1}}function f(e,t){const r=[];let n=0,o=0;for(;n<e.length&&o<t.length;)e[n]<t[o]?(r.push(e[n]),n++):(r.push(t[o]),o++);for(;n<e.length;)r.push(e[n]),n++;for(;o<t.length;)r.push(t[o]),o++;return r}function l(e){return Math.max(...e.map((e=>String(e).length)))}function y(e,t){let r=String(e);const n=r.length-1-t;return r=n>=0?r[n]:void 0,["+","-"].includes(r)?-1:r?+r:0}function p(e){let t=0,r=1;const n=e.length,o=new Array(n).fill(0);for(;r<n;)e[t]===e[r]?(o[r]=t+1,t++,r++):0!==t?t=0:r++;return o}e.binarySearch=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r?.sort&&e.sort(s("function",r?.sortMethod)?r.sortMethod:(e,t)=>e-t);let n=0,o=e.length-1;for(;n<=o;){const r=n+Math.floor((o-n)/2);if(e[r]===t)return r;t<e[r]?o=r-1:n=r+1}return-1},e.binarySearchRecursive=function e(t,r,n,o){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},c=n,i=o;if(void 0===n&&void 0===o&&(c=0,i=t.length-1,a?.sort&&t.sort(s("function",a?.sortMethod)?a.sortMethod:(e,t)=>e-t)),i<=c&&t[c]!==r)return-1;const u=c+Math.floor((i-c)/2);return t[u]===r?u:r<t[u]?e(t,r,c,u-1,a):e(t,r,u+1,i,a)},e.bubbleSort=function(e){const t=e.length;let r=!0;for(;r;){r=!1;for(let n=0;n<t;n++)if(e[n]>e[n+1]){const t=e[n];e[n]=e[n+1],e[n+1]=t,r=!0}}return e},e.factorial=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(t?.cache&&void 0!==r[e])return r[e];if(e<3)return e;const n=[0,1,2];for(let t=3;t<=e;t++)n[t]=t*n[t-1];const o=n[n.length-1];return t?.cache&&void 0===r[e]&&(r[e]=o),o},e.factorialRecursive=function e(r){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(n?.cache&&void 0!==t[r])return t[r];if(r<3)return n?.cache&&void 0===t[r]&&(t[r]=r),r;const o=r*e(r-1,n);return n?.cache&&void 0===t[r]&&(t[r]=o),o},e.fibonacci=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(t?.cache&&void 0!==o[e])return o[e];if(e<2)return e;const r=[0,1];for(let t=2;t<=e;t++)r[t]=r[t-1]+r[t-2];const n=r[r.length-1];return t?.cache&&void 0===o[e]&&(o[e]=n),n},e.fibonacciRecursive=function e(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(r?.cache&&void 0!==n[t])return n[t];if(t<2)return r?.cache&&void 0===n[t]&&(n[t]=t),t;const o=e(t-1,r)+e(t-2,r);return r?.cache&&void 0===n[t]&&(n[t]=o),o},e.getDigit=y,e.insertionSort=function(e){const t=e.length;for(let r=1;r<t;r++){const t=e[r];let n=r-1;for(;n>=0&&e[n]>t;)e[n+1]=e[n],n--;e[n+1]=t}return e},e.kmp=function(e,t){const r=e.length,n=t.length,o=p(t);let a=0,c=0;for(;a<r;)if(e[a]===t[c]?(a++,c++):c>0?c=o[c-1]:a++,c===n)return!0;return!1},e.longestPrefixSuffix=p,e.maxDigits=l,e.mergeSort=function e(t){if(t.length<=1)return t;const r=t.length,n=Math.floor(r/2);return f(e(t.slice(0,n)),e(t.slice(n)))},e.mergeSortResolve=f,e.naiveSearch=function(e,t){if(t.length>e.length)return!1;for(let r=0;r<e.length;r++)for(let n=0;n<t.length&&e[r+n]===t[n];n++)if(n===t.length-1)return!0;return!1},e.quickSort=function e(t){const r=t.length;if(r<=1)return t;const n=t[r-1];let o=0;const a=[],c=[];for(;o<r-1;)t[o]<n?a.push(t[o]):c.push(t[o]),o++;return[...e(a),n,...e(c)]},e.radixSort=function(e){let t=e;const r=l(t);for(let e=0;e<r;e++){const r=Array.from({length:11},(()=>[]));for(let n=0;n<t.length;n++){r[y(t[n],e)+1].push(t[n])}t=r.flatMap((e=>e))}return t},e.selectionSort=function(e){const t=e.length;for(let r=0;r<t;r++){let n=r;for(let o=r+1;o<t;o++)e[o]<e[n]&&(n=o);if(n!==r){const t=e[r];e[r]=e[n],e[n]=t}}return e},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AmauiAlgorithms={})}(this,(function(e){"use strict";const t={};const r={};const n={};const o={};var a="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};const c={},i="undefined"!=typeof window&&void 0!==window.document,u=!(void 0===a||"undefined"==typeof module||!module.exports);function s(e,t){var r;let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const o={...c,...n},{variant:a}=o,f=t&&"object"==typeof t&&Object.getPrototypeOf(t);switch(e){case"string":return"string"==typeof t;case"number":return"number"==typeof t&&!Number.isNaN(t);case"boolean":return"boolean"==typeof t;case"array":return Array.isArray(t);case"object":return"object"==typeof t&&!!t&&t.constructor===Object;case"object-like":return"object"==typeof t&&(null===t||t.constructor!==Object);case"class":return("object"==typeof t||"function"==typeof t)&&(/class/gi.test(String(t))||/class/gi.test(String(null==t?void 0:t.constructor)));case"function":return!!(t&&t instanceof Function);case"async":return!(!s("function",t)||!(i?"AsyncFunction"===t.constructor.name:t()instanceof Promise));case"map":return!(f!==Map.prototype);case"weakmap":return!(f!==WeakMap.prototype);case"set":return!(f!==Set.prototype);case"weakset":return!(f!==WeakSet.prototype);case"promise":return!(f!==Promise.prototype);case"int8array":return!(f!==Int8Array.prototype);case"uint8array":return!(f!==Uint8Array.prototype);case"uint8clampedarray":return!(f!==Uint8ClampedArray.prototype);case"int16array":return!(f!==Int16Array.prototype);case"uint16array":return!(f!==Uint16Array.prototype);case"int32array":return!(f!==Int32Array.prototype);case"uint32array":return!(f!==Uint32Array.prototype);case"float32array":return!(f!==Float32Array.prototype);case"float64array":return!(f!==Float64Array.prototype);case"bigint64array":return!(f!==BigInt64Array.prototype);case"biguint64array":return!(f!==BigUint64Array.prototype);case"typedarray":return s("int8array",t)||s("uint8array",t)||s("uint8clampedarray",t)||s("int16array",t)||s("uint16array",t)||s("int32array",t)||s("uint32array",t)||s("float32array",t)||s("float64array",t)||s("bigint64array",t)||s("biguint64array",t);case"dataview":return!(f!==DataView.prototype);case"arraybuffer":return!(f!==ArrayBuffer.prototype);case"sharedarraybuffer":return"undefined"!=typeof SharedArrayBuffer&&!(f!==SharedArrayBuffer.prototype);case"symbol":return!("symbol"!=typeof t);case"error":return!!(t&&t instanceof Error);case"date":return!!(t&&t instanceof Date);case"regexp":return!!(t&&t instanceof RegExp);case"arguments":return!(!t||"[object Arguments]"!==t.toString());case"null":return null===t;case"undefined":return void 0===t;case"blob":return i&&t instanceof Blob;case"buffer":return!(!u||"function"!=typeof(null==t||null===(r=t.constructor)||void 0===r?void 0:r.isBuffer)||!t.constructor.isBuffer(t));case"element":if(t)switch(a){case void 0:case"html":case"element":return i&&("object"==typeof HTMLElement?t instanceof HTMLElement:t&&"object"==typeof t&&null!==t&&1===t.nodeType&&"string"==typeof t.nodeName);case"node":return i&&("object"==typeof Node?t instanceof Node:t&&"object"==typeof t&&null!==t&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName);case"react":return t.elementType||t.hasOwnProperty("$$typeof");default:return!1}return!1;case"simple":return s("string",t,o)||s("number",t,o)||s("boolean",t,o)||s("undefined",t,o)||s("null",t,o);case"not-array-object":return!s("array",t,o)&&!s("object",t,o);default:return!1}}function f(e,t){let r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];const n=[];let o=0,a=0;for(;o<e.length&&a<t.length;)(r?e[o]<t[a]:e[o]>t[a])?(n.push(e[o]),o++):(n.push(t[a]),a++);for(;o<e.length;)n.push(e[o]),o++;for(;a<t.length;)n.push(t[a]),a++;return n}function l(e){return Math.max(...e.map((e=>String(e).length)))}function y(e,t){let r=String(e);const n=r.length-1-t;return r=n>=0?r[n]:void 0,["+","-"].includes(r)?-1:r?+r:0}function p(e){let t=0,r=1;const n=e.length,o=new Array(n).fill(0);for(;r<n;)e[t]===e[r]?(o[r]=t+1,t++,r++):0!==t?t=0:r++;return o}e.binarySearch=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r?.sort&&e.sort(s("function",r?.sortMethod)?r.sortMethod:(e,t)=>e-t);let n=0,o=e.length-1;for(;n<=o;){const r=n+Math.floor((o-n)/2);if(e[r]===t)return r;t<e[r]?o=r-1:n=r+1}return-1},e.binarySearchRecursive=function e(t,r,n,o){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},c=n,i=o;if(void 0===n&&void 0===o&&(c=0,i=t.length-1,a?.sort&&t.sort(s("function",a?.sortMethod)?a.sortMethod:(e,t)=>e-t)),i<=c&&t[c]!==r)return-1;const u=c+Math.floor((i-c)/2);return t[u]===r?u:r<t[u]?e(t,r,c,u-1,a):e(t,r,u+1,i,a)},e.bubbleSort=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=e.length;let n=!0;for(;n;){n=!1;for(let o=0;o<r;o++)if(t?e[o]>e[o+1]:e[o]<e[o+1]){const t=e[o];e[o]=e[o+1],e[o+1]=t,n=!0}}return e},e.factorial=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(t?.cache&&void 0!==r[e])return r[e];if(e<3)return e;const n=[0,1,2];for(let t=3;t<=e;t++)n[t]=t*n[t-1];const o=n[n.length-1];return t?.cache&&void 0===r[e]&&(r[e]=o),o},e.factorialRecursive=function e(r){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(n?.cache&&void 0!==t[r])return t[r];if(r<3)return n?.cache&&void 0===t[r]&&(t[r]=r),r;const o=r*e(r-1,n);return n?.cache&&void 0===t[r]&&(t[r]=o),o},e.fibonacci=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(t?.cache&&void 0!==o[e])return o[e];if(e<2)return e;const r=[0,1];for(let t=2;t<=e;t++)r[t]=r[t-1]+r[t-2];const n=r[r.length-1];return t?.cache&&void 0===o[e]&&(o[e]=n),n},e.fibonacciRecursive=function e(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{cache:!0};if(r?.cache&&void 0!==n[t])return n[t];if(t<2)return r?.cache&&void 0===n[t]&&(n[t]=t),t;const o=e(t-1,r)+e(t-2,r);return r?.cache&&void 0===n[t]&&(n[t]=o),o},e.getDigit=y,e.insertionSort=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=e.length;for(let n=1;n<r;n++){const r=e[n];let o=n-1;for(;o>=0&&(t?e[o]>r:e[o]<r);)e[o+1]=e[o],o--;e[o+1]=r}return e},e.kmp=function(e,t){const r=e.length,n=t.length,o=p(t);let a=0,c=0;for(;a<r;)if(e[a]===t[c]?(a++,c++):c>0?c=o[c-1]:a++,c===n)return!0;return!1},e.longestPrefixSuffix=p,e.maxDigits=l,e.mergeSort=function e(t){let r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t.length<=1)return t;const n=t.length,o=Math.floor(n/2),a=e(t.slice(0,o),r),c=e(t.slice(o),r);return f(a,c,r)},e.mergeSortResolve=f,e.naiveSearch=function(e,t){if(t.length>e.length)return!1;for(let r=0;r<e.length;r++)for(let n=0;n<t.length&&e[r+n]===t[n];n++)if(n===t.length-1)return!0;return!1},e.quickSort=function e(t){let r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const n=t.length;if(n<=1)return t;const o=t[n-1];let a=0;const c=[],i=[];for(;a<n-1;)(r?t[a]<o:t[a]>o)?c.push(t[a]):i.push(t[a]),a++;return[...e(c,r),o,...e(i,r)]},e.radixSort=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=e;const n=l(r);for(let e=0;e<n;e++){const n=Array.from({length:11},(()=>[]));for(let o=0;o<r.length;o++){const a=y(r[o],e);n[t?a+1:10-(a+1)].push(r[o])}r=n.flatMap((e=>e))}return r},e.selectionSort=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=e.length;for(let n=0;n<r;n++){let o=n;for(let a=n+1;a<r;a++)(t?e[a]<e[o]:e[a]>e[o])&&(o=a);if(o!==n){const t=e[n];e[n]=e[o],e[o]=t}}return e},Object.defineProperty(e,"__esModule",{value:!0})}));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc