P is for Practical | |
PerlMonks |
Re: A better way of lookup?by KurtSchwind (Chaplain) |
on Apr 28, 2015 at 11:38 UTC ( [id://1124994]=note: print w/replies, xml ) | Need Help?? |
So in both perl and javascript you can use the same algorithm if you'd like. Start with an arrary with all of your breakpoint values. I'll abridge here.
Then push the new value in. For our example I'll push in 50123.
Sort them. Do an index-of on your value - 1. In javascript this is actually cleaner than perl. The sort in javascript doesn't have to do a copy at the end and it has the 'indexOf' operator built in. </code>
-- “For the Present is the point at which time touches eternity.” - CS Lewis
In Section
Seekers of Perl Wisdom
|
|