Skip to content

Array.reduce only accepts two arguements #17

@donaldzhu

Description

@donaldzhu

The transpiled Array.reduce only accepts two arguments (source array and callback). This is how it's transpiled:

var _reduce = function _reduce(array, callback)

The following code will not run correctly as it discards the initial value:

const foo = [1, 2].reduce((prev, curr) => {
  prev.push(curr + 1)
  return prev
}, [])

Transpiled code:

(function () {
  // prev.push is not a function
  var foo = _reduce([1, 2], function (prev, curr) {
    prev.push(curr + 1)
    return prev
  }) // no initial value
})()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions