-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.js
More file actions
127 lines (86 loc) · 3.07 KB
/
Copy pathmain.js
File metadata and controls
127 lines (86 loc) · 3.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var api = {};
/*
PART 1: Implement fanOut.
fanOut - return a new collection of results after applying the
input function to each item in the input collection.
args: input - input collection
fn - function to apply to each item in the collection
EX: - fanOut([1, 2, 3], double) --> [1, 4, 9];
function double(n) { return n * n; }
Restrictions:
- Do not use make any function calls (other than fn and push)
- You may not use any external libraries
*/
api.fanOut = function(input, fn) {
// TODO: your implementation here.
return [];
};
/*
PART 2: Implement funnel.
funnel - return an result after applying an accumulation function to
each item in the collection. Funneling down to a single result.
args: input - input collection
fn - function to apply to each item in the collection with
args accumulation value and current value
startValue - start the accumulation with this value
EX: - funnel([1, 2, 3], add, 0) --> 6;
- funnel([1, 2], add, 1) --> 4
function add(total, n) { return total + n; }
Restrictions:
- Do not use make any function calls (other than fn and push)
- You may not use any external libraries
*/
api.funnel = function(input, fn, startValue){
// TODO: your implementation here.
return 0;
};
/*
PART 3: Implement distill.
distill - return a new collection of results after applying the
predicate function to each item. Only include the item in the result
if the predicate returns true.
args: input - input collection
fn - predicate function to apply to each item in the collection
EX: - distill([1, 2, 3], isEven) --> [2];
- distill([1, 2, 3], isOdd) --> [1, 3];
- distill([1, 2, 3], isNegative) --> [];
Restrictions:
- Do not use make any function calls (other than fn and push)
- You may not use any external libraries
*/
api.distill = function(input, fn){
// TODO: your implementation here.
return [];
};
/*
PART 4: Implement numberOfChars.
numberOfChars - return the number of characters in the input array of strings
args: input - input collection of strings (words)
EX: - numberOfChars(['the']) --> 3;
- numberOfChars(['the', 'end']) --> 6;
Restrictions:
- You MAY use fanOut, funnel, and distill, and the length property
- You may not use make any other function calls
- You may not use any external libraries
*/
api.numberOfChars = function(input){
// TODO: your implementation here
return 0;
};
/*
PART 5: Implement numberOfCertainChars.
numberOfCertainChars - return the number of c characters in the input array of strings
args: input - input collection of strings (words)
c - the certain character to count
EX: - numberOfCertainChars(['the'], 'e') --> 1;
- numberOfCertainChars(['the', 'end'], 'e') --> 2;
Restrictions:
- You MAY use fanOut, funnel, and distill, and the length property
- You may not use make any other function calls
- You may not use any external libraries
*/
api.numberOfCertainChars= function(input, c){
// TODO: your implementation here
return 0;
};
module.exports = api;