Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello experts,

I have array say
var arr = [20,100,50,200]


What I need:

I need function which return highest close value from given number (supplied) . Suppose I supplied value

1) 48 then return value should be 50
2) 50 then return value should be 50
3) 10 then return value should be 20
4) 150 then return value should be 200

I appreciate minimal code.

Thanks in advance!!!
Posted

1 solution

var arr = [20,100,50,200];
arr.sort();
for ( var i=0; i<arr.length;>  if(arr[i]>input)
  {
    alert(arr[i]);
    break;
  }
}
 
Share this answer
 
Comments
Kiran Sonawane 27-Jul-11 3:26am    
Hi Prerak, Thanks for reply. Can you please check your code once again.
Prerak Patel 27-Jul-11 4:08am    
You can change it yourself. input is the value to be passed. And if you got any error, specify the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900