map returns undefined

node v8.14.0
version: 1.0.0
endpointsharetweet
const products = [ { id: 1, name: 'product 1', description: '******', }, { id: 2, name: 'product 2', description: '******', }, { id: 3, name: 'product 3', description: '******', }, { id: 4, name: 'product 4', description: '******', }, { id: 5, name: 'product 5', description: '******', }, { id: 6, name: 'product 6', description: '******', }, { id: 7, name: 'product 7', description: '******', }, { id: 8, name: 'product 8', description: '******', }, { id: 9, name: 'product 9', description: '******', }, { id: 10, name: 'product 10', description: '******', } ] balancePerProduct = [ { day: '2018-08-10', status: 'onDemand', }, { day: '2018-08-11', status: 'onDemand', }, { day: '2018-08-12', status: 'onDemand', }, { day: '2018-08-13', status: 'onDemand', }, { day: '2018-08-14', status: 'onDemand', }, { day: '2018-08-15', status: 'onDemand', }, { day: '2018-08-16', status: 'onDemand', } ] const retroInfoPerProduct = [{ day: '2018-08-10', status: 'onDemand', }, { day: '2018-08-11', status: 'available', }, { day: '2018-08-12', status: 'onDemand', }, { day: '2018-08-13', status: 'available', }, { day: '2018-08-14', status: 'available', }, { day: '2018-08-15', status: 'available', }, { day: '2018-08-16', status: 'available', }] const retroPerProduct = (products) => { result = [] products.map(product => { finalResult = balancePerProduct.map((date, index) => ({ day: date.day, status: date.status === retroInfoPerProduct[index].status ? date.status : 'onDemand', })); globalStatus = finalResult.some(date => date.status === 'onDemand') ? 'onDemand' : 'available'; result.push(Object.assign(product, { retro_information: { dates_info: finalResult, globalStatus, }, })); }); return result; } console.log('retroPerProduct:', retroPerProduct(products));
Loading…

no comments

    sign in to comment