Hello,
I’m working on such issue
//You have a fashion catalog, an inventory of items from various high-fashion designers.
// Each designer has a lineup of shoes. Each shoe has a name and a price.
//It looks like this:
var currentInventory = [
{
name: 'Brunello Cucinelli',
shoes: [
{name: 'tasselled black low-top lace-up', price: 1000},
{name: 'tasselled green low-top lace-up', price: 1100},
{name: 'plain beige suede moccasin', price: 950},
{name: 'plain olive suede moccasin', price: 1050}
]
},
{
name: 'Gucci',
shoes: [
{name: 'red leather laced sneakers', price: 800},
{name: 'black leather laced sneakers', price: 900}
]
}
];
//Look up all the shoes across all the designers and list them out in a array of array with format:
//[[designer name, shoe name, price], [designer name. shoe name, price], ....]
//E.g.
/*[
[Brunello Cucinelli, tasselled black low-top lace-up, 1000],
[Brunello Cucinelli, tasselled green low-top lace-up, 1100],
...
*/]
// My solution
function renderInventory(inventory) {
var outPutArray = [];
inventory.map(items =>{
for(var i = 0; i < items.shoes.length; i++){
outPutArray.push(`${items.name}, ${items.shoes[i].name}, ${items.shoes[i].price}`)
}
});
return outPutArray;
}
var output = renderInventory(currentInventory);
console.log(output);
My output of this solution is only single list array
like this
[ 'Brunello Cucinelli, tasselled black low-top lace-up, 1000',
'Brunello Cucinelli, tasselled green low-top lace-up, 1100',
'Brunello Cucinelli, plain beige suede moccasin, 950',
'Brunello Cucinelli, plain olive suede moccasin, 1050',
'Gucci, red leather laced sneakers, 800',
'Gucci, black leather laced sneakers, 900' ]
But I need the array of arrays format.
maybe somebody could give some suggestion about it?