title: Implement the *logger* function which will prepare data for logging
body: <p>I have a task to
  Implement the <em>logger</em> function which will prepare data for logging.It should have default service configuration <code>{serviceName: 'global', serviceId: 1}</code><br />
  Some examples:</p>
  <pre><code> // {&quot;3-0&quot;:&quot;[auth_service] Wrong email&quot;,&quot;3-1&quot;:&quot;[auth_service] Wrong password&quot;,&quot;3-2&quot;:&quot;[auth_service] Success login&quot;}
    logger(['Wrong email', 'Wrong password', 'Success login'], {serviceName: 'auth_service', serviceId: 3});
  
    // {&quot;1-0&quot;:&quot;[global] Fatal error&quot;,&quot;1-1&quot;:&quot;[global] Data corrupted&quot;}
    logger(['Fatal error', 'Data corrupted']);
  </code></pre>
  <p>It should be written using Typescript.
  I started to make this function but i dont know how to make it look like the example or like test samples..
  This is what i did till now :</p>
  <pre><code>function logger(data: [], serviceInfo: {}) {
      //It should have default service configuration `{serviceName: 'global', serviceId: 1}`
      if (serviceInfo == undefined) {
          serviceInfo = {
              serviceName: &quot;global&quot;,
              serviceId: 1,
          };
      } else {
       let obj = {
          
       }
       return obj;
      }
  }
  </code></pre>
  <p>And unit tests:</p>
  <pre><code>describe('logger', () =&gt; {
      it('should log user events', () =&gt; {
          const result = logger(['User Event 1', 'User Event 2'], {serviceName: 'user', serviceId: 12});
          const expected = {
              '12-0': '[user] User Event 1',
              '12-1': '[user] User Event 2',
          };
          assert.deepStrictEqual(result, expected)
      });
  
      it('should log auth events', () =&gt; {
          const result = logger(['Event 1', 'Event 2', 'Event 3'], {serviceName: 'auth', serviceId: 2});
          assert.strictEqual(result['2-1'], '[auth] Event 2')
      });
  
      it('should log global events', () =&gt; {
          const result = logger(['Event 1', 'Event 2', 'Event 3']);
          assert.strictEqual(result['1-2'], '[global] Event 3')
      });
  });
  </code></pre>
  <p>I thought about pushing the array into a different object,but i dont know how to make that depending on serviceId to appear like:</p>
  <pre><code>{
  '12-0':'[user] User event 1'
  }
  </code></pre>
  <p>where 12 is the service id, 0 is the array item index, [user] is the serviceName and the user event 1 is the array item.. I'm new in Javascript and Typescript and idk all the nuances.
  Could you help me please? Thanks in advance!</p>
  <p>Edit: I tried a little and came up with this function :</p>
  <pre><code>function logger(data: [], serviceInfo: {}) {
      //It should have default service configuration `{serviceName: 'global', serviceId: 1}`
    serviceInfo = {
        serviceName : 'Gigi',
        serviceId : 0
    }
  
      if (serviceInfo == undefined) {
          serviceInfo = {
              serviceName: &quot;global&quot;,
              serviceId: 1,
          };
      } 
      let obj={}
      //obj[serviceInfo.serviceId.value + ]
  
      data.forEach(function (value, i) {
          //console.log('%d: %s', i, value);
          obj[serviceInfo.serviceId.value +'-'+ i] = '[' + serviceInfo.serviceName.value + ']' + value
      });
      console.log(obj)
  }
  </code></pre>
  <p>But in console i get :</p>
  <pre><code>{
    'undefined-0': '[undefined]User Event 1',
    'undefined-1': '[undefined]User Event 2'
  }
  {
    'undefined-0': '[undefined]Event 1',
    'undefined-1': '[undefined]Event 2',
    'undefined-2': '[undefined]Event 3'
  }
  {
    'undefined-0': '[undefined]Event 1',
    'undefined-1': '[undefined]Event 2',
    'undefined-2': '[undefined]Event 3'
  }
  </code></pre>
  <p>How to acces serviceName and serviceId if data is get from input not from function?</p>