npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jmapreduce

v0.1.1

Published

map reduce for nodejs

Downloads

5

Readme

jmapreduce

a map reduce for nodejs

install

$ npm install --save jmapreduce

test

$ npm test

usage

var JMapReduce = require('jmapreduce'); 

example

general usage

var JMapReduce = require('jmapreduce');
var input = "A MapReduce program is composed of a Map() procedure (method) that\n" +
        " performs filtering and sorting\n" +
        "(such as sorting students by first name into queues,\n" +
        " one queue for each name) and a Reduce() method that \n" +
        "performs a summary operation (such as counting the number\n" +
        " of students in each queue, yielding name frequencies).\n\n" +
        " The 'MapReduce System' (also called 'infrastructure' or 'framework')\n" +
        " orchestrates the processing by marshalling\n\n\n" +
        " the distributed servers, running the various tasks in parallel,\n" +
        " managing all communications and data transfers\n" +
        " between the various parts of the system, and providing for redundancy\n" +
        " and fault tolerance.\n" +
        " The model is inspired by the map and reduce functions commonly\n" +
        " used in functional programming, although their \n" +
        "purpose in the MapReduce framework is not the same as in their\n" +
        " original forms. The key contributions of \n" +
        "the MapReduce framework are not the actual map and reduce functions,\n" +
        " but the scalability and fault-tolerance\n" +
        " achieved for a variety of applications by optimizing\n" +
        " the execution engine once. As such, a single-threaded\n" +
        " implementation of MapReduce will usually not be faster than\n" +
        " a traditional (non-MapReduce) implementation,\n" +
        " any gains are usually only seen with multi-threaded implementations.\n" +
        " The use of this model is beneficial\n" +
        " only when the optimized distributed shuffle operation (which reduces\n" +
        " network communication cost) and fault tolerance\n" +
        " features of the MapReduce framework come into play. Optimizing the communication\n" +
        " cost is essential to a good MapReduce algorithm.";

    var jmapReduce = new JMapReduce();
      jmapReduce.textData(input)
          .flatMap(function(data){
              return data.match(/[^\s]+|\s+[^\s+]$/g);
          })
          .map(function(x){
              return {key: x, value: 1};
          })
          .groupByKey()
          .reduce(0, function(a,b){
              return a + b;
          })
          .sort(function(a, b){
              return b.value - a.value;
          });
   
   // print ten first elements   
   console.log("%s", JSON.stringify(jmapReduce.toArray().slice(0, 10), null, 2));
   
   // from console 
    [
      {
        "key": "the",
        "value": 16
      },
      {
        "key": "and",
        "value": 9
      },
      {
        "key": "of",
        "value": 8
      },
      {
        "key": "a",
        "value": 7
      },
      {
        "key": "MapReduce",
        "value": 6
      },
      {
        "key": "is",
        "value": 5
      },
      {
        "key": "in",
        "value": 5
      },
      {
        "key": "by",
        "value": 4
      },
      {
        "key": "The",
        "value": 4
      },
      {
        "key": "for",
        "value": 3
      }
    ]

#textData(data) data: a string or an array of strings

  var jmapReduce = new JMapReduce();
  jmapReduce.textData('text data sample');
  jmapReduce.textData(['this is ', 'an example', ' for reading data']);