Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-footstone

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-footstone - npm Package Compare versions

Comparing version 0.1.1-alpha.0 to 0.1.1-alpha.1

5

package.json
{
"name": "data-footstone",
"version": "0.1.1-alpha.0",
"version": "0.1.1-alpha.1",
"description": "data structure",

@@ -29,3 +29,3 @@ "author": "feigebaobei <18515195415@163.com>",

"clean": "echo 'fo clean'",
"compile": "tsc",
"compile": "tsc && npm run rollup",
"prepare": "npm run compile",

@@ -35,3 +35,2 @@ "pretest": "npm run compile",

"prettier": "prettier",
"prepublish": "npm run tsc && npm run rollup",
"p": "prettier --write .",

@@ -38,0 +37,0 @@ "pc": "prettier --check ."

94

tscDist/src/order.js

@@ -1,7 +0,89 @@

let bubbleSort = () => { };
let selectSort = () => { };
let insertSort = () => { };
let quickSort = () => { };
let quickSortSelf = () => { };
// n^2
let bubbleSort = (arr, order = 'asc') => {
let len = arr.length;
for (let i = 0; i < len; i++) {
for (let j = 0; j < len - i - 1; j++) {
switch (order) {
case 'asc':
if (arr[j] > arr[j + 1]) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
break;
case 'des':
if (arr[j] > arr[j + 1]) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
break;
}
}
}
};
let selectSort = (arr) => {
for (let i = 0; i < arr.length - 1; i++) {
let minIndex = i;
for (let j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
if (minIndex !== i) {
[arr[i], arr[minIndex]] = [arr[minIndex], arr[i]];
}
}
};
let merge = (leftArr, rightArr) => {
let tempArr = [];
while (leftArr.length && rightArr.length) {
if (leftArr[0] < rightArr[0]) {
tempArr.push(leftArr.shift());
}
else {
tempArr.push(rightArr.shift());
}
}
return [...tempArr, ...leftArr, ...rightArr];
};
// nlogn
let mergeSort = (arr) => {
if (arr.length < 2) {
return arr;
}
let m = arr.length >> 1;
let left = arr.slice(0, m);
let right = arr.slice(m);
return merge(mergeSort(left), mergeSort(right));
};
// n^2
let insertSort = (arr) => {
for (let i = 1; i < arr.length; i++) {
let cur = arr[i];
let lastIndex = i - 1;
while (lastIndex >= 0 && arr[lastIndex] > cur) {
arr[lastIndex + 1] = arr[lastIndex];
lastIndex--;
}
arr[lastIndex + 1] = cur;
return arr;
}
};
// nlogn
let quickSort = (arr) => {
if (arr.length < 1) {
return arr;
}
let p = arr[arr.length >> 1];
let left;
let right;
arr.forEach(item => {
if (item > p) {
right.push(item);
}
else {
left.push(item);
}
});
return [...(quickSort(left)), ...(quickSort(right))];
};
let heapSort = () => { };
let binarySearch = () => { };
export { bubbleSort, selectSort, insertSort, quickSort, quickSortSelf, binarySearch, };
export { bubbleSort, selectSort, insertSort, quickSort, heapSort, binarySearch, };
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