Skip to content

Commit 489d8cf

Browse files
committed
Merge pull request timoxley#107 from thirtified/fix-map-reduce-solution
Fixed map-with-reduce solution to correctly process array entries
2 parents 1d6ff0b + 2a428a5 commit 489d8cf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

exercises/implement_map_with_reduce/exercise.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ var numbers = Array.apply(null, {length: Math.random() * 20 + 1}).map(function()
1010
return randomInt(0, 9)
1111
})
1212

13-
module.exports = runner(numbers, function(item) { return item * 3 })
13+
module.exports = runner.custom(function(map, numbers) {
14+
var result = []
15+
result.push('non-array entries', map(numbers, function(item) { return item * 3 }))
16+
result.push('array entries', map(numbers, function(item) { return [item * 3] }))
17+
return result
18+
})(numbers)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = function map(arr, fn, thisArg) {
22
return arr.reduce(function(acc, item, index, arr) {
3-
return acc.concat(fn.call(thisArg, item, index, arr))
3+
acc.push(fn.call(thisArg, item, index, arr))
4+
return acc
45
}, [])
56
}

0 commit comments

Comments
 (0)