i have an easy coding challenge, we have an array of objects:
const banners = [
{
country: 'fr',
type: 'mobile',
category: 'adult'
},
{
country: 'fr',
type: 'mobile',
category: 'non adult'
},
{
country: 'fr',
type: 'desktop',
category: 'adult'
},
{
country: 'ru',
type: 'mobile',
category: 'adult'
},
{
country: 'ru',
type: 'mobile',
category: 'non adult'
},
{
country: 'ru',
type: 'desktop',
category: 'adult'
},
]
and i want a javaScript function that takes an array and a list of object keys to build a tree:
fn(banners, ['country', 'type', 'category'])
which returns:
{
fr: {
mobile: {
adult: [Array],
['non adult']: [Array]
},
desktop: {
adult: [Array],
['non adult']: [Array]
}
},
ru: {
mobile: {
adult: [Array],
['non adult']: [Array],
},
desktop: {
adult: [Array],
['non adult']: [Array],
}
}
}
really stucked with this challenge and need to save the time, anybody help to get a clean implementation. lodash solutions also accepted.
I have good knowledge of PHP, Ajax, Jquery and Javascript. I able to do this task very well with good quality. Our main motto is client satisfaction and makes a long-term relationship with you. Thank you
Hello,
As I understand from the sample, the key at index 0 in the array will be the top parent, then index 1 will be the child of 0 and parent of 2 and so on.
Need a bit clarification on:
adult: [Array] - why is this an array?
['non-adult'] - This is not a valid key. What to do about this?
Should the function take keys array of any length?
Do contact me when available.
Mateen
Not that hard, won't take too long.
Depends on what language you want it, C, C++, Java or Python, Javascript.
Python and Javascript will be the fastest to implement, then java and C++ and least will be C.
Looking at the job, it doesn't even seem to be a job that offers $10, and I also think my bid ($5) is too much for this job.