-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhigher-order_functions
35 lines (32 loc) · 1 KB
/
higher-order_functions
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
function reduceRight(arr, starting, func){
for(var i = arr.length; i >= 0; i -=1){
function reduce(arr[i]){ //reduce takes each element in array and reassigns the value to the reverse index
arr[i-arr.length]=func(i);
}
reduce(arr[i]);
}
if(starting === number){ //defines rules to print transformed array
return number += arr.forEach(
function(ele){
return number += ele;
});
}else if(Array.isArray(starting) && starting.length = 0){
return arr.slice();
}else{
return '{'+ arr + '}';
}
}
function reduceRight(arr, starting, func){
if(arr.length === 0){
return starting;
}else{
if(starting === number){
starting += func(arr[-1]) += reduceRight(arr.slice(0,-2),starting, func);
}else if(Array.isArray(starting) && starting.length = 0){
starting.unshift(func(arr[-1])) += reduceRight(arr.slice(0,-2),starting,func);
}else{
starting + func(arr[-1]) += reduceRight(arr.slice(0,-2),starting,func);
}
}
return starting;
}