First of all, our makeProducts function will take the two arrays as its parameters. Using the .forEach() method of arrays, we'll iterate over each item in the first array, naming the values multiplicant:
const makeProducts = function(array1, array2) {
array1.forEach( (multiplicant) => {
if (!products[multiplicant]) {
products[multiplicant] = { }
}
array2.forEach( (multiplier) => {
if (!products[multiplier]) {
products[multiplier] = { }
}
products[multiplicant][multiplier] = multiplicant * multiplier
products[multiplier][multiplicant] = products[multiplicant]
[multiplier]
})
})
}
Now, our end goal is to have an object that will tell us "the product of x and y is z." If we abstract this into using an object as a data store, we could arrive at a structure like this:
{
x: {
y: z
},
y: {
x: z
}
}
In this object structure, all we need to do to retrieve...