Hi Retool Team,
I am not very versed in JS and would like to seek help the JS for the following transformation
input = [
{index: 1, location: HKG, product: Food},
{index: 1, location: HKG, product: Wood},
{index: 1, location: HKG, product: Clothing},
{index: 2, location: SGH, product: Food},
{index: 2, location: SGH, product: Wood},
{index: 2, location: SGH, product: Clothing}
]
output = [
{index: 1, location: HKG, product: [Food, Wood, Clothing]},
{index: 2, location: SGH, product: [Food, Wood, Clothing]
]
My code below fails to execute and returns "equipment.push() is not a function"
let max_index = _.max(input.index)
let input = _.orderBy(input, 'index', 'asc')
let output = [], product = [], location=[]
while (i <= max_index) {
for (let item of input){
if (item.index == i) {
product.push(item.product)
location.push(item.location)
}
}
product = _.uniq(product)
location = _.uniq(location).toString()
output.push({
index: i,
product: product,
location:location
})
i++;
}
return output