deduplication 1.0.3 → 1.0.6

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.
Files changed (2) hide show
  1. package/index.js +20 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,16 +2,32 @@
2
2
  * 数组去重
3
3
  * @param arr 要去重的数组
4
4
  * @param type number type为1表示使用set函数去重,type为2表示使用
5
+ * @param sort string sort的值为default表示不排序,为asc表示自增排序,为desc表示为自减
5
6
  */
6
- function deduplication(arr,type=1) {
7
+ function deduplication(arr,type=1,sort='default') {
8
+ let newArr=[];
9
+ //判断去重的方式
7
10
  switch(type){
8
11
  case 1:
9
- return method1(arr);
12
+ newArr=method1(arr);
10
13
  break;
11
14
  case 2:
12
- method2(arr);
15
+ newArr=method2(arr);
13
16
  break;
14
17
  }
18
+ //判断排序的类型
19
+ switch (sort) {
20
+ case "default":
21
+ return newArr;
22
+ case "asc":
23
+ return newArr.sort((a,b)=>{
24
+ return a-b;
25
+ });
26
+ case "desc":
27
+ return newArr.sort((a,b)=>{
28
+ return b-a;
29
+ });
30
+ }
15
31
 
16
32
  }
17
33
  module.exports=deduplication;
@@ -26,3 +42,4 @@ function method1(arr){
26
42
  function method2(arr) {
27
43
 
28
44
  }
45
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deduplication",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "repository": "",
6
6
  "author": "henry",