title: Algorithm: Next Greater Element I (from leetcode)
body: <p>can someone please tell me what I'm missing in solving this algorithm? One problem I have is that my first if statement inside the nested loop is not evaluating, but I don't know why it wouldn't evaluate.</p>
  
  <p><strong>Here is the description of the problem:</strong> </p>
  
  <p><em>You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.
  The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, output -1 for this number.</em></p>
  
  <p><strong>Example 1:</strong></p>
  
  <p>Input: nums1 = [4,1,2], nums2 = [1,3,4,2].</p>
  
  <p>Output: [-1,3,-1]</p>
  
  <p>Explanation:
      For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1.
      For number 1 in the first array, the next greater number for it in the second array is 3.
      For number 2 in the first array, there is no next greater number for it in the second array, so output -1.</p>
  
  <p><a href="https://leetcode.com/problems/next-greater-element-i/#/description" rel="nofollow noreferrer">link to original description</a></p>
  
  <p><strong>And here is my code so far:</strong></p>
  
  <pre><code> var nums1 = [4,1,2];
   var nums2 = [1,3,4,2];
  
    var nextGreaterElement = function(findNums, nums) {
      var holder = [];
  
      for (var i = 0; i &lt; findNums.length; i++) {
  
       //loop through the 2nd array starting at the index of the first loop's current item. 
  
        for (var j = nums.indexOf(findNums[i]); i &lt; nums.length - j; i++) {
  
          if (nums[j+1] &gt; nums[j]) {
            holder.push(nums[j+1]);
            break;
          } 
  
          if (nums[nums.length]) {
            holder.push(-1);
          }
        }
      }
      return holder;
  };
  
  nextGreaterElement(nums1, nums2)
  </code></pre>
  
  <p>Thanks for any help.</p>