title: Filtering the inputs in Node.js
body: <p>Here, I am fetching a data from the user. The first line contains an integer, denoting the number of entries in the phone book. 
  Each of the  subsequent lines describes an entry in the form of  space-separated values on a single line. The first value is a <strong>friend's name</strong>, and the second value is a <strong>digit phone number</strong>.</p>
  
  <p>For example:</p>
  
  <pre><code>2
  sam 99912222
  tom 11122222
  </code></pre>
  
  <p>So, while processing this input, I am taking the number of entries from the user and assigning it to variable <code>noOfIterations</code>. For the subsequent entries, I am assigning it to a list of objects wherein the format will be : for eg. <code>[{ sam: '99912222' },{ tom: '11122222' }]</code>.</p>
  
  <p>But the problem is I get <code>[ 'sam 99912222', 'tom 11122222' ]</code> instead while consoling the <code>map</code> variable. Why do I get this?</p>
  
  <pre><code>function processData(input) {
      var noOfIterations = 0;
       var map = input.split('\n').filter(function (string, index){
          if(index===0){
              noOfIterations = parseInt(string);
          }
          else{
              var splitStrings = string.trim().split(' ');
              var obj = {};
              obj[splitStrings[0]] =  splitStrings[1];
              console.log(obj);
              return obj;
          } 
       });
       console.log(map);
  } 
  
  process.stdin.resume();
  process.stdin.setEncoding("ascii");
  _input = "";
  process.stdin.on("data", function (input) {
      _input += input;
  });
  
  process.stdin.on("end", function () {
     processData(_input);
  });
  </code></pre>