On Tue, Aug 18, 2015 at 12:00 PM, bala prasanna <[email protected]> wrote: > Hi, i suddenly come up with this > Array.prototype.reduce(); > > In the following program, if we pass an array "inputWords", of stings. > it will return an object with keys as words (unique), and values as "no of > times occurred" > > function countWords(inputWords) { > return inputWords.reduce(function(countMap, word) { > countMap[word] = ++countMap[word] || 1 // increment or initialize to 1 > return countMap > }, {}) // second argument to reduce initialises countMap to {} > } > > module.exports = countWords > > I would like to know the implementation of .reduce() > > Anyone , please suggest me , how to find the source code of this/ or > implement an one such > > I appreciate your help , on spending your valuable time on this funny > question. Since i am a beginner , i don't know how to go and see the source > code of the module. > But i come to know v8 is open source, hence there might be a way.. > Thanks for your help in advance . > > Thanks and regards, > Bala
The implementation is in src/array.js, grep for ArrayReduce. Most built-in objects are implemented partially or entirely in JS, in the src/*.js files, but there is a large body of supporting C++ code. I'd start in src/runtime (e.g. runtime-array.cc) and work your way from there. -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
