From 4de003c74e1cf67dc2bcbdfdfe552f070cf011d3 Mon Sep 17 00:00:00 2001 From: Naomi Date: Fri, 23 Jan 2015 15:53:06 -0600 Subject: [PATCH] Fully implement map with reduce [Array.prototype.arg](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) allows you to pass the context to call the callbacks in. This is a more complete implementation. --- problems/implement_map_with_reduce/solution.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/implement_map_with_reduce/solution.js b/problems/implement_map_with_reduce/solution.js index 1e3f5d3..4c9ca8a 100644 --- a/problems/implement_map_with_reduce/solution.js +++ b/problems/implement_map_with_reduce/solution.js @@ -1,5 +1,5 @@ -module.exports = function map(arr, fn) { +module.exports = function map(arr, fn, thisArg) { return arr.reduce(function(acc, item, index, arr) { - return acc.concat(fn(item, index, arr)) + return acc.concat(fn.call(thisArg, item, index, arr)) }, []) }