What is Map/Reduce?

前端 未结 7 1661
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 07:18

I hear a lot about map/reduce, especially in the context of Google\'s massively parallel compute system. What exactly is it?

相关标签:
7条回答
  • 2020-12-07 07:57

    Map is a native JS method that can be applied to an array. It creates a new array as a result of some function mapped to every element in the original array. So if you mapped a function(element) { return element * 2;}, it would return a new array with every element doubled. The original array would go unmodified.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

    Reduce is a native JS method that can also be applied to an array. It applies a function to an array and has an initial output value called an accumulator. It loops through each element in the array, applies a function, and reduces them to a single value (which begins as the accumulator). It is useful because you can have any output you want, you just have to start with that type of accumulator. So if I wanted to reduce something into an object, I would start with an accumulator {}.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce?v=a

    0 讨论(0)
提交回复
热议问题