Fashion Inventory algorithm

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?

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://freecodecamp.org.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

Actually, your current solution is an array containing string elements. One simple way to use your existing solution is to push a literal array with the 3 references you were using in your template literal. Just abandon the whole template literal approach.

An example of how you push an array into another array is as follows:

var outerArr = [];
outerArr.push([1, 2, 3,4]);
outerArr.push([5, 6, 7, 8]);
console.log(outerArr);

The above displays the following in the console:

[ 
  [ 1, 2, 3, 4 ],
  [ 5, 6, 7, 8 ]
]

You could actually solve this with reduce and map and avoid the for loop, but I will show you that approach once you solve using your current method.

1 Like