---
# System prepended metadata

title: Sumit

---

# Sumit


```javascript=

const orderArr = [
 { order_id: "O001", seller_id: "S01", status: 'placed'},
 { order_id: "O003", seller_id: "S02", status: 'ofd'},
 { order_id: "O002", seller_id: "S01", status: 'dispatched'},
 { order_id: "O004", seller_id: "S01", status: 'dispatched'},
]

const orderHash = {
    S01 : {
        placed: ["O001"],
        dispatched: ["O002", "0004"]
    },
    S02: {
        ofd: ["O003"]
    }
}

// O(n)
function formatOrders(orderArr) {
    const response ={}
    while(orderArr.length){
        let seller = orderArr.shift()
        const orderBySeller = orderArr.filter(val=> val.seller_id == seller.seller_id)
        orderBySeller.push(seller)
        const temp = {}
        while(orderBySeller.length){
            let order = orderBySeller.shift()
            const data = orderBySeller.map(val=>{
               if( val.status == order.status) return val.order_id
                })
            temp[`${order.status}`]= data
        }
        response[`${seller.seller_id}`] = temp
        
    }    
    return response
    
}


var obj = {a: 23, g: {rk: 23, the: [32, {tw: 99}]}}
var arr  = ['g', 'the', 1, 'tw']


function path(obj, arr) {
    if(arr.length>0){
        const x = arr.shift()
        try{
         if(arr.length>1){ 
                obj = obj[x] 
                path(obj,arr)
        }
        else{
             if(obj[x]) return obj[x]
             else return false
                }
        }catch(e){
            console.log(e)
                return false
        }
       
    }else{
    return false
    }
    
}





```