---
# System prepended metadata

title: Anupam kumar

---

# Anupam kumar

# Question 1: Find the 2nd largest number in an array
```javascript=
let max = -Infinity;
let index = -1;
for(var i=0; i<arr.length; i++){
    if(arr[i]>max){
        max = arr[i];
    }
}
for(var i=0; i<arr.length; i++){
    if(arr[i] == max){
        index = i;
    }
}
let max = -Infinity;
for(var i=0; i<arr.length; i++){
    if(arr[i]>max){
        max = arr[i];
    }
}
console.log(max);

let max1 = -Infinity;
let max2 = -Infinity;
for(var i=0; i<arr.length; i++){
    if(max1<arr[i]){
        max1 = arr[i];
    }
    if(max2<arr[i] && max2<max1){
        max2 = arr[i];
    }
}






```

# Question 2: Js transformation. 
```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, O004]
    },
    S02: {
        ofd: [O003]
    }
}
let orderH = {};
for(var i=0; i<orderArr.length; i++){
    if(orderH[orderArr[i].seller_id] == null){
          let arr1 = [];
         arr1.push(orderArr[i].order_id);
        orderH[orderArr[i].seller_id] = {    
          
            orderArr[i].status = arr1;
        }
    }else{
        if(orderH[orderArr[i].status] == null){
            orderH[orderArr[i].status] = [orderArr[i].order_id]
        }else{
            orderH[orderArr[i].status].push(orderArr[i].order_id);
        }
      
    }
}


```