Current approach:
function stuff() {
const days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
const names ['tom', 'dave', 'kate', 'jane', 'james']
const result = {}
days.map(day => {
const innerResult = {}
names.map(name => {
// some logic
const res = {
result: 'some result'
}
innerResult[name] = res
})
result[day] = innerResult
})
return result
}
which would look something like:
{
"monday": {
"tom": {
result: 'some result'
},
"dave": {
result: 'some result'
},
"kate": {
result: 'some result'
},
"jane": {
result: 'some result'
},
"james": {
result: 'some result'
},
},
"tuesday": {
// ...etc
}
}
is this possible to achieve without the use of mutable variables such as result
and innerResult
, can I return this structure straight from the map or something along those lines...
For instance, something like:
function stuff() {
const days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
const names ['tom', 'dave', 'kate', 'jane', 'james']
return days.map(day => {
return { [day]: names.map(name => {
return {
[name]: { result: 'some result' }
}
})}
})
}
obviously the structure on those won't match but something along those lines, any help would be appreciated.