deduplication 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +18 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -15,20 +15,27 @@ function deduplication(arr,type=1,sort='default') {
15
15
  newArr=method2(arr);
16
16
  break;
17
17
  }
18
+
19
+ let sortArr;
18
20
  //判断排序的类型
19
21
  switch (sort) {
20
22
  case "default":
21
- return newArr;
23
+ sortArr = newArr;
24
+ break;
22
25
  case "asc":
23
- return newArr.sort((a,b)=>{
26
+ sortArr = newArr.sort((a,b)=>{
24
27
  return a-b;
25
28
  });
29
+ break;
26
30
  case "desc":
27
- return newArr.sort((a,b)=>{
31
+ sortArr = newArr.sort((a,b)=>{
28
32
  return b-a;
29
33
  });
34
+ break;
30
35
  }
31
36
 
37
+ return sortArr;
38
+
32
39
  }
33
40
  module.exports=deduplication;
34
41
 
@@ -39,7 +46,13 @@ function method1(arr){
39
46
  return [...a];
40
47
  }
41
48
 
49
+ //indexOf方法
42
50
  function method2(arr) {
43
-
51
+ let arr2 = [];
52
+ for(let i=0;i<arr.length;i++){
53
+ if(arr2.indexOf(arr[i]) === -1){
54
+ arr2.push(arr[i]);
55
+ }
56
+ }
57
+ return arr2;
44
58
  }
45
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deduplication",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "main": "index.js",
5
5
  "repository": "",
6
6
  "author": "henry",