Skip to content

Commit

Permalink
feat: add uniqArray func, remove outdate hasX.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
suressk committed Jul 1, 2022
1 parent a8ff46e commit 22201ac
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 33 deletions.
25 changes: 24 additions & 1 deletion array/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isFunction } from '../is'

/**
* Used to remove an item of the array
*
Expand All @@ -11,6 +13,27 @@ export const removeArrayItem = <T>(arr: T[], el: T) => {
}
}

/**
* Used to remove the mutiple items (shallow uniq)
*
* @param arr need uniq array
*/
export const uniqArray = <T extends any>(arr: T[]) => {
if (!arr || !arr.length) {
return []
}
if (Set && isFunction(Set)) {
return Array.from(new Set(arr))
}
// // 兼容方案,暂时未实现
// const res = []
// const usedMap = new Map() || {}
// for (const item of arr) {
// }
return arr
}

export default {
removeArrayItem
removeArrayItem,
uniqArray
}
13 changes: 0 additions & 13 deletions hasChanged.ts

This file was deleted.

15 changes: 0 additions & 15 deletions hasOwnProp.ts

This file was deleted.

8 changes: 5 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Array funcs */
import { removeArrayItem } from './array'
import { removeArrayItem, uniqArray } from './array'

// is funcs
import {
Expand Down Expand Up @@ -45,7 +45,8 @@ export {
hasChanged,
getPrototype,
debounce,
removeArrayItem
removeArrayItem,
uniqArray
}

export default {
Expand All @@ -68,5 +69,6 @@ export default {

debounce,

removeArrayItem
removeArrayItem,
uniqArray
}
2 changes: 1 addition & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
// "$schema": "https://json.schemastore.org/tsconfig",
"include": ["."],
"compilerOptions": {
"module": "CommonJS",
Expand Down

0 comments on commit 22201ac

Please sign in to comment.