showing results for - "intersection of two deep objects in javascript"
Glenn
16 Mar 2018
1const company = {
2    lastYearRevenue: 4444,
3    capacityInstalled: 22,
4    ppaDemands: [ 'f6202f82501ee7350cc73fd', '5f6211ef0b5983761f4d0bb8' ],
5    activeProjects: [
6      '5f6204162501ee7350cc7406',
7      'f6207462501ee7350cc7408',
8      '5f62411e21a66a8a5ca6d51f'
9    ],
10    companyGroup: 'kjkj',
11    invoicingAddress: '',
12    businessAddress: 'jk',
13    legalEntityVatNumber: 'kjkj',
14    legalEntity: 'jkj',
15    balancingPartyBiddingZones: [
16      {
17        key: 'balancingPartyBiddingZones',
18        value: 'Albania',
19        label: 'Albania'
20      },
21      {
22        key: 'balancingPartyBiddingZones',
23        value: 'Barbados',
24        label: 'Barbados'
25      }
26    ],
27    tradingLicenseBiddingZones: [
28      {
29        key: 'tradingLicenseBiddingZones',
30        value: 'Albania',
31        label: 'Albania'
32      },
33      {
34        key: 'tradingLicenseBiddingZones',
35        value: 'Barbados',
36        label: 'Barbados'
37      }
38    ],
39    isABalancingParty: 'Yes',
40    hasTradingLicense: 'Yes',
41    ableToProvideFirming: 'Yes',
42    leaveNamingRights: 'Yes',
43    provideAnotherStructure: '',
44    tradingLicense: '1111',
45    requireNamingRights: 'Yes',
46    signedPpaBefore: 'No',
47    parentCompanyGuarantee: 'No',
48    offerInvestmentGrade: 'Yes',
49    structureProposed: '',
50    regionPresent: '',
51    creditRating: ' 1111',
52    acceptSellersTerms: '',
53    historyOfPpa: [],
54    favourites: [],
55    cleanBuyersAssociation: 'RE100',
56    linkToCompany: '',
57    signedPpaMarketing: '',
58    acceptBuyersTerms: '',
59    twoYearPipeline: 22,
60    willingToAggregate: 'Yes',
61    targetReached: '2034',
62    amountOfEnergyBuying: '',
63    procurementTarget: '98',
64    locations: [],
65    energy: [],
66    sector: 'Agriculture',
67    companyName: '',
68    users: [ '5e6f76572097e12186c46e4b' ],
69    profileType: '',
70    email: '',
71    userName: ''
72  }
73
74const payload =   { cleanBuyersAssociation: 'RE00' } 
75
76  const getDifference = (a, b) => {
77    const entries = Object.entries(b)
78    const filteredEntries = Object.entries(b).filter(([key, val]) => key in a )
79    console.log(entries)
80    console.log('Object.fromEntries(entries) = ', Object.fromEntries(entries))
81    console.log('filteredEntries = ', filteredEntries)
82    console.log('Object.fromEntries(filteredEntries) = ', Object.fromEntries(filteredEntries))
83    // Object.entries(b)
84    return Object.fromEntries(Object.entries(b).filter(([key, val]) => {
85      return key in a
86      // && a[key] !== val
87    }))
88  }
89  
90   const toReturn = getDifference(payload, company)
91
92console.log('toReturn: ', toReturn)
93
94    const entries = Object.entries(company)
95    console.log(entries)
96
97getDifference(payload, company)
98
99
100
101
similar questions