title: How to find first element that's less than the x in an array in Javascript?
body: <p>I have this question in which I wanted to loop through an array starting from large number to smaller number and compare the number in the array against the x provided. </p>
  
  <p>My code was supposed to be like this:</p>
  
  <pre><code>function convertToRoman(num) {
  
    var decimalNum = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
  
    while (num &gt; 0){ // to prevent the number from reaching zero
      for (var k = 0; k &lt; decimalNum.length; k++) { //to loop through the array
  
      if(num &gt; decimalNum[k]) {return k}; //this is the part in which I wanted to return the element that is next in the array that is less than the num
      }
    }
  
  
  }
  
  convertToRoman(36);
  </code></pre>
  
  <p>For example, if the num = 36, then the next number in the array that is less than 36 would be 10. So I wanted to return 10. How do I do that?</p>
  
  <p>I tried to find solutions online but the only solutions I found was for Java or C++ which is completely different from JavaScript, correct? And I don't think that binary search should be used as well...</p>