-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-object-manipulation
More file actions
90 lines (77 loc) · 1.7 KB
/
string-object-manipulation
File metadata and controls
90 lines (77 loc) · 1.7 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function map(object,function){ //looping in array
for(var i = 0; i < object.length; i += 1){
(function map(ele, function){
return function(ele);
})(object[i]);
}
return object;
}
function doubler(ele){ //doubler
return ele * 2;
}
map(object, function(ele){ return ele * 3;}); //tripler?
function filter(object, function){ //filter
var newArray=[];
return object.map(function(object, function){
if(filter(object[i]){
newArray.push(object[ele]);
}
});
}
function contains(object, ele){
if(Array.isArray(object) && object !== null){ //function for arrays
return object.map(function(){
if(object.indexOf(ele)){
return true;
}
return false;
}
}else{ //function for objects
for (var k in object){
if(Object.hasOwnProperty(k)){
if(contains(object[k]) === ele){
return true;
}
return false;
}
}
}
}
function countWords(string,function){
var sum = 1;
string.map(function(string,function){
if(countWords(string[i]) === ' '){
sum += 1;
}
}
return sum;
}
function reduce(object, start, function){
var current= start;
return object.map(function(object, function){
current = function(start, object[ele]);
});
return current;
}
function sum(object){
return object.map(function(object, function){
return object[i] + object[i+1];
})
}
function every(object, function){
return object.reduce(function(object,1,function){
if(function(object)){
return true;
}
return false;
});
}
function any(object function){
return object.reduce(function(object,switch,function){
switch = false;
if(function(object)){
switch = true;
}
return switch;
})
}