Skip to content

Conversation

gs20060101
Copy link

The function "fn" is a user-supplied function that would not take "index" and "arr" arguments.

The function "fn" is a user-supplied function that would not take "index" and "arr" arguments.
@aonghusonia
Copy link

aonghusonia commented May 9, 2018

the callback function supplied to Array.prototype.map() takes three arguments:

currentValue: The current element being processed in the array.
index (Optional): The index of the current element being processed in the array.
array (Optional): The array map was called upon.

the tests pass even if you leave the second two out (see below) but I think the official solution is more complete with them

module.exports = function map(arr, fn) {
  return arr.reduce(function(acc, item, index) {
    acc[index] = (fn(item))
    return acc
  }, [])
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants