-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.js
More file actions
executable file
·47 lines (47 loc) · 1.07 KB
/
array.js
File metadata and controls
executable file
·47 lines (47 loc) · 1.07 KB
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
rad.flusharray=function(a){
while(a.length>0){
a.pop();
}
}
//http://stackoverflow.com/questions/5767325/how-to-remove-a-particular-element-from-an-array-in-javascript
rad.removefromarray=function(a,elem){
var i = a.indexOf(elem);
if (i > -1) {
a.splice(i, 1);
}
}
rad.indexstringtoarray=function(str){
//takes a string of 0-10,12,15,20-22 and makes an array
var a = [];
var sections = str.split(",");
for(var s = 0; s<sections.length; s++){
var dashSections = sections[s].split('-');
if(dashSections.length>1){
var start=parseInt(dashSections[0]);
var end=parseInt(dashSections[1]);
for(var step=start; step<=end;step++){
a.push(step);
}
}else{
var v=parseInt(sections[s]);
a.push(v);
}
}
return a;
}
rad.cleararraypastindex=function(array,index){
if (index >= array.length || index < 0) {
console.log("cleararraypastindex, index out of bounds")
return array;
}
array.splice(index);
return array;
}
rad.pushunique=function(arr,item){
if(arr.indexOf(item) === -1) {
arr.push(item);
return true;
}else{
return false;
}
}