@zhouyihang/js-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/package.json +45 -0
- package/src/algorithms/index.js +16 -0
- package/src/algorithms/myAtoi.js +19 -0
- package/src/algorithms/removeDuplicateLetters.js +29 -0
- package/src/algorithms/removeKdigits.js +25 -0
- package/src/algorithms/sort.js +117 -0
- package/src/algorithms/threeSum.js +34 -0
- package/src/algorithms/twoSum.js +23 -0
- package/src/algorithms/validParentheses.js +22 -0
- package/src/algorithms/wordDictionary.js +27 -0
- package/src/data-structures/index.js +1 -0
- package/src/data-structures/queue.js +46 -0
- package/src/dom/index.js +1 -0
- package/src/dom/traverseEl.js +19 -0
- package/src/framework/hashRouter.js +25 -0
- package/src/framework/historyRouter.js +35 -0
- package/src/framework/index.js +4 -0
- package/src/framework/reactive.js +56 -0
- package/src/framework/vdom.js +37 -0
- package/src/index.js +66 -0
- package/src/javascript/curry.js +8 -0
- package/src/javascript/index.js +2 -0
- package/src/javascript/inheritance.js +23 -0
- package/src/patterns/index.js +3 -0
- package/src/patterns/proxyObserver.js +30 -0
- package/src/patterns/pubsub.js +30 -0
- package/src/patterns/singleton.js +32 -0
- package/src/polyfills/call.js +54 -0
- package/src/polyfills/deepClone.js +36 -0
- package/src/polyfills/deepFreeze.js +11 -0
- package/src/polyfills/index.js +8 -0
- package/src/polyfills/iterator.js +13 -0
- package/src/polyfills/jsonStringify.js +27 -0
- package/src/polyfills/new.js +7 -0
- package/src/polyfills/promise.js +99 -0
- package/src/polyfills/promiseMethods.js +67 -0
- package/src/types/index.d.ts +1 -0
- package/src/types/nestedArray.d.ts +3 -0
- package/src/utils/asyncPool.js +21 -0
- package/src/utils/chunkArr.js +10 -0
- package/src/utils/debounce.js +11 -0
- package/src/utils/flatten.js +40 -0
- package/src/utils/formatSizeUnits.js +13 -0
- package/src/utils/index.js +10 -0
- package/src/utils/makeTree.js +17 -0
- package/src/utils/mergeArr.js +18 -0
- package/src/utils/parseUrl.js +13 -0
- package/src/utils/throttle.js +14 -0
- package/src/utils/toTree.js +23 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// 合并两个有序数组
|
|
2
|
+
function mergeArr(arr1, arr2) {
|
|
3
|
+
let i = 0,
|
|
4
|
+
j = 0;
|
|
5
|
+
const result = [];
|
|
6
|
+
while (i < arr1.length && j < arr2.length) {
|
|
7
|
+
if (arr1[i] < arr2[j]) {
|
|
8
|
+
result.push(arr1[i++]);
|
|
9
|
+
} else {
|
|
10
|
+
result.push(arr2[j++]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
while (i < arr1.length) result.push(arr1[i++]);
|
|
14
|
+
while (j < arr2.length) result.push(arr2[j++]);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default mergeArr;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function parseUrl(url) {
|
|
2
|
+
const obj = {};
|
|
3
|
+
const query = url.split("?")[1];
|
|
4
|
+
if (!query) return obj;
|
|
5
|
+
|
|
6
|
+
query.split("&").forEach((item) => {
|
|
7
|
+
const [key, value] = item.split("=");
|
|
8
|
+
obj[key] = decodeURIComponent(value || "");
|
|
9
|
+
});
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default parseUrl;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// 扁平数据结构转树
|
|
2
|
+
function toTree(data) {
|
|
3
|
+
const result = [];
|
|
4
|
+
if (!Array.isArray(data)) return result;
|
|
5
|
+
|
|
6
|
+
const map = {};
|
|
7
|
+
data.forEach((item) => {
|
|
8
|
+
map[item.id] = item;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
data.forEach((item) => {
|
|
12
|
+
const parent = map[item.parentId];
|
|
13
|
+
if (parent) {
|
|
14
|
+
(parent.children || (parent.children = [])).push(item);
|
|
15
|
+
} else {
|
|
16
|
+
result.push(item);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default toTree;
|