var data=[10,25,50,10,20,80,30,30,40,90]; function fun(arr,index){ var min=Math.min.apply(this,arr); if(index<=0){ return min; }else{ arr=arr.filter((item)=>{return item!=min;}); if(arr.length==0){ return min; } return fun(arr,--index) } } console.log(fun(data,2));
var data=[10,25,50,10,20,80,30,30,40,90]; function fun(arr,index){ arr.sort((a,b)=>{return a-b;}); var min_index=0,min=arr[0]; if(index==0){ return min; } for(var i=0;i=index){ break; } } } return min; } console.log(fun(data,2));