Last active
June 28, 2018 18:14
-
-
Save adnanmc/ace14bc03c68a2fb0cf2ca486fc0597d to your computer and use it in GitHub Desktop.
This file contains 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
var _ = require('lodash'); | |
const data = [ | |
{ | |
MediaAssetId: 0, | |
Exposure: null, | |
QtyImps: null, | |
QV: null, | |
AvgAttendance: null, | |
Games: null, | |
SportId: 0, | |
TotalExposure: 0, | |
TotalImpressions: 0, | |
MediaValue: 0, | |
Id: 'c925e3f8-2abb-4e11-becc-bdf11e32c4e8', | |
Name: 'xcontainer - root', | |
CampaignId: null, | |
IsActive: true, | |
ParentId: null, | |
IsNew: null, | |
IsContainer: true, | |
hasChildren: true | |
}, | |
{ | |
MediaAssetId: 0, | |
Exposure: null, | |
QtyImps: null, | |
QV: null, | |
AvgAttendance: null, | |
Games: null, | |
SportId: 0, | |
TotalExposure: 0, | |
TotalImpressions: 0, | |
MediaValue: 0, | |
Id: '5cc7fcc0-ba28-40cc-ba57-0ed29baa2ccc', | |
Name: 'xcontainer - 1', | |
CampaignId: null, | |
IsActive: true, | |
ParentId: 'c925e3f8-2abb-4e11-becc-bdf11e32c4e8', | |
IsNew: null, | |
IsContainer: true, | |
hasChildren: true | |
}, | |
{ | |
MediaAssetId: 0, | |
Exposure: 40, | |
QtyImps: 200, | |
QV: 0.75, | |
AvgAttendance: 100, | |
Games: 3, | |
SportId: 0, | |
TotalExposure: 120, | |
TotalImpressions: 24000, | |
MediaValue: 18000, | |
Id: '7ef89eca-5943-43ce-af8c-32a353e07ee5', | |
Name: 'xtgrh', | |
CampaignId: null, | |
IsActive: true, | |
ParentId: '5cc7fcc0-ba28-40cc-ba57-0ed29baa2ccc', | |
IsNew: null, | |
IsContainer: false, | |
hasChildren: false | |
}, | |
{ | |
MediaAssetId: 0, | |
Exposure: 50, | |
QtyImps: 30, | |
QV: 0.5, | |
AvgAttendance: 200, | |
Games: 100, | |
SportId: 0, | |
TotalExposure: 10000, | |
TotalImpressions: 300000, | |
MediaValue: 150000, | |
Id: '9737b525-5e78-4bde-9f5b-75573650e0e2', | |
Name: 'xew', | |
CampaignId: null, | |
IsActive: true, | |
ParentId: '5cc7fcc0-ba28-40cc-ba57-0ed29baa2ccc', | |
IsNew: null, | |
IsContainer: false, | |
hasChildren: false | |
} | |
]; | |
let shit = (data) => { | |
let copy = data; | |
_.each(copy, (x) => { | |
let oldId = x['Id']; | |
let newId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = (Math.random() * 16) | 0, | |
v = c == 'x' ? r : (r & 0x3) | 0x8; | |
return v.toString(16); | |
}); | |
x['Id'] = newId; | |
_.each(copy, (y) => { | |
if (y['ParentId'] == oldId) { | |
y['ParentId'] = newId; | |
} | |
}) | |
}); | |
return copy; | |
}; | |
let sample = shit(data); | |
console.log(sample); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment