var temp = []; function Insert(num) { var len = temp.length; if(len == 0){ temp.push(num); }else{ var i = len - 1; while(i >= 0 && temp[i] > num){ temp[i+1] = temp[i]; i--; } temp[i+1] = num; } } function GetMedian() { if( temp.length % 2 == 1 ){ return temp[(temp.length-1)/2]; }else{ return (temp[temp.length/2] + temp[temp.length/2-1])/2; } } /*var temp = []; function Insert(num) { // write code here temp = num.sort(); return temp; } function GetMedian(){ // write code here var len = temp.length; if( len % 2 != 0 ){ var n = (len-1)/2; return temp[n]; }else if(len % 2 == 0){ var m = len/2; return (temp[m]+temp[m-1])/2; } } */