Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:22:08+00:00 2026-06-11T21:22:08+00:00

Code: var some_var = [/*…….*/]; var compare_var; for (var i = 0; i <

  • 0

Code:

var some_var = [/*.......*/];
var compare_var;
for (var i = 0; i < some_var.length - 1; i++){
    if (some_var[i] <= compare_var && compare_var < some_var[i + 1]){
        return some_var[i];
    }
}

One value of some_var is 30 and the next one is 40 and the next one is 50 and compare_var is 42.

It wouldn’t return 30 even though it’s less-than 42, because 42 isn’t less-than 40. Which also means that it would return 40 because it’s less-than 42 and 42 is less-than 50.

Edit:

As someone mentioned code translation is not exactly great for SE.so. Just to make it clear: I did try several different things in ruby. I have way more experience in javascript though, so the best way I could think of to phrase my question was to write what I needed out in javascript so that I could see how it translated into ruby. Thanks for the answers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:22:09+00:00Added an answer on June 11, 2026 at 9:22 pm

    This is a one-liner:

    some_var.select{|v| v < compare_var}.max
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: for(var i in this.units) { if(this.units[i].x==att.x && this.units[i].y==att.y){} //... some
Please, consider the code below: template<typename T> bool function1(T some_var) { return true; }
Following is my code for Ajax request: for(some loop) { var SOME-VARIABLE = value;
My understanding is nothing will happen. For instance this code: foreach (var some in
Here is some code: var class = function(elem,div){ this.elem= elem; this.div = div; this.init
function superman(){ //some code var opitem = $(#opinionitem).html(); opitem.replace(:opinionid,valid string); //more code } gives
Suppose I have a Javascript file function js_main(args){ /* some code */ var x
I have the following code in specman: var x := some.very.long.path.to.a.variable.in.another.struct; while (x ==
I have some code like this: var mySelect = document.getElementById(mySelect); mySelect.innerHTML = <option>Loading...</option>; $.get(ajaxPage.php,
I have some code like this: var content = document.getElementById('myDivId'); function MyFunction() { alert(content.style.height);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.