Created
June 18, 2019 05:40
-
-
Save nishanbajracharya/8fe38807b3ad074a7da2072c7b8e701b to your computer and use it in GitHub Desktop.
Normalize input to get output.
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
// From this | |
var input = { | |
'1': { | |
id: 1, | |
name: 'John', | |
children: [ | |
{ id: 2, name: 'Sally' }, | |
{ id: 3, name: 'Mark', children: [{ id: 4, name: 'Harry' }] } | |
] | |
}, | |
'5': { | |
id: 5, | |
name: 'Mike', | |
children: [{ id: 6, name: 'Peter' }] | |
} | |
}; | |
// To this | |
var output = { | |
'1': { id: 1, name: 'John', children: [2, 3] }, | |
'2': { id: 2, name: 'Sally' }, | |
'3': { id: 3, name: 'Mark', children: [4] }, | |
'4': { id: 4, name: 'Harry' }, | |
'5': { id: 5, name: 'Mike', children: [6] }, | |
'6': { id: 6, name: 'Peter' } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment