This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Array.prototype.union = ( array ) => { | |
| const concatenated = this.concat( array ); | |
| return concatenated.filter( ( item, pos ) => concatenated.indexOf( item ) === pos ); | |
| }; | |
| // example | |
| [ 'a', 'b', 'c' ].union([ 'b', 'c', 'd', 'e' ]); // [ 'a', 'b', 'c', 'd', 'e' ] | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "singleQuote": true, | |
| "useTabs": true, | |
| "tabWidth": 2, | |
| "trailingComma": "es5", | |
| "endOfLine": "lf", | |
| "printWidth": 80, | |
| "semi": true | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const response1 = [ | |
| { id: 1, productName: 'Chair' }, | |
| { id: 2, productName: 'Table' }, | |
| ]; | |
| const requiredResponse1Output = [ | |
| { id: 1, product: { name: 'Chair' } }, | |
| { id: 2, product: { name: 'Table' } }, | |
| ]; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const response1 = [ | |
| { id: 1, productName: 'Chair' }, | |
| { id: 2, productName: 'Table' }, | |
| ]; | |
| const requiredResponse1Output = [ | |
| { id: 1, product: { name: 'Chair' } }, | |
| { id: 2, product: { name: 'Table' } }, | |
| ]; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const response1 = [ | |
| { id: 1, productName: 'Chair' }, | |
| { id: 2, productName: 'Table' }, | |
| ]; | |
| const requiredResponse1Output = [ | |
| { id: 1, product: { name: 'Chair' } }, | |
| { id: 2, product: { name: 'Table' } }, | |
| ]; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function mapProductName(transactionsArray) { | |
| return transactionsArray | |
| .map( | |
| ({ productName, ...rest }) => ({ | |
| ...rest, | |
| product: { name: productName } | |
| }), | |
| ); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const response2 = [ | |
| { transactionId: 1, productName: 'Desk' }, | |
| { transactionId: 2, productName: 'Clock' }, | |
| ]; | |
| const requiredResponse2Output = [ | |
| { id: 1, product: { name: 'Desk' } }, | |
| { id: 2, product: { name: 'Clock' } }, | |
| ]; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function mapTransactionIdIntoId(transactionsIarray) { | |
| return transactionsIarray | |
| .map( ({ transactionId, ...rest }) => ({ | |
| ...rest, | |
| id: transactionId, | |
| }) ) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function responseMapper(response, mapperFunctions) { | |
| return mapperFunctions.reduce( | |
| (result, mapper) => mapper(result), | |
| response | |
| ); | |
| } | |
| // And call it like this | |
| const result1 = responseMapper(response1, [ | |
| mapProductName, | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const response3 = [ | |
| { purchaseId: 21, productName: 'Bag' }, | |
| { purchaseId: 22, productName: 'Lamp' }, | |
| ]; | |
| const requiredOutput3 = [ | |
| { productId: 31, purchaseId: 21, product: { name: 'Bag' } }, | |
| { productId: 32, purchaseId: 22, product: { name: 'Lamp' } }, | |
| ]; | 
OlderNewer