-
Notifications
You must be signed in to change notification settings - Fork 0
/
array-plus.js
48 lines (36 loc) · 964 Bytes
/
array-plus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Array.prototype.pushIfNotPresent = function (pValue){
var lArray = this || [];
if (lArray.indexOf(pValue) == -1){
lArray.push(pValue);
return true;
}
return false;
}
Array.prototype.hasValue = function (pValue){
var lArray = this || [];
return lArray.indexOf(pValue) != -1;
}
Array.prototype.removeDuplicatedValues = function (){
var lArray = this || [];
var lLength = lArray.length;
for (var i = lLength - 1; i > -1; i--){
if (lArray.indexOf(lArray[i]) != i){
lArray.splice(i, 1);
}
}
if (lLength != lArray.length){
return true;
}
return false;
}
Array.prototype.countOf = function (pValue){
var count = 0;
var lArray = this || [];
var lLength = lArray.length
for (var i = 0 ; i < lLength; i++){
if (lArray[i] == pValue){
count++;
}
}
return count;
}