Skip to content

Commit 780fc7c

Browse files
committed
Added additional hint for reduce
1 parent cc4147f commit 780fc7c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

2013-02-03-assignment.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,21 @@ reduce([1, 2, 3], function (memo, x) { return memo.concat([x * 2]); }, []); // =
113113

114114
### Hint
115115

116-
Choosing an appropirate default value for the `seed` may be tricky. The flow should be given seed -> first element -> undefined. So if an empty array is passed in, and no seed is provided, the result should be undefined.
116+
Choosing an appropirate default value for the `seed` may be tricky. The flow should be given seed -> first element -> `undefined`. So if an empty array is passed in, and no seed is provided, the result should be `undefined`.
117117

118118
A memoizer should be kept that is initialized to the value of the `seed`, and then passed along to the function `fn` along with each successive element. The value of this memoizer should be being set at each step.
119119

120+
To check for whether a seed value is passed in can be done with the following:
121+
```javascript
122+
function reduce (xs, fn, seed) {
123+
if (typeof seed === 'undefined') {
124+
// seed value was not passed in
125+
} else {
126+
// seed value was passed in
127+
}
128+
}
129+
130+
120131
---
121132

122133
## Q5: Prototypal Inheritance

0 commit comments

Comments
 (0)