title: What is the time complexity of Javascript Array.reduce() and Array.find()?
body: <p>I am trying to return an array of indexes of values that add up to a given target. I am trying to solve it the fastest way I can!</p>
  
  <p>Examples:</p>
  
  <pre class="lang-js prettyprint-override"><code>sumOfTwo([1, 2, 4, 4], 8)   // =&gt; [2, 3]
  sumOfTwo([1, 2, 3, 9], 8)   // =&gt; []
  </code></pre>
  
  <p>So first I tried a simple brute-force. (Time complexity: <strong>O(n^2)</strong> )</p>
  
  <pre class="lang-js prettyprint-override"><code>function sumOfTwo(arr, target) {
    for (let i = 0; i &lt; arr.length; i++) {
      for (let j = i + 1; j &lt; arr.length; j++) {
        if (arr[i] + arr[j] === target) {
          return [i, j];
        }
      }
    }
  
    return [];
  }
  </code></pre>
  
  <p>Then I tried: (Time complexity: sorting <strong>O(n log n)</strong> + for loop <strong>O(n)</strong>)</p>
  
  <pre class="lang-js prettyprint-override"><code>function sumOfTwo(arr, target) {
    const sortedArr = arr.sort();
    let idxFromBack = arr.length - 1;
  
    for (let [idx, val] of sortedArr.entries()) {
      if (val + arr[idxFromBack] &gt; target) {
        idxFromBack--;
      }
  
      if (val + arr[idxFromBack] === target) {
        return [idx, idxFromBack];
      }
    }
  
    return [];
  }
  </code></pre>
  
  <p>Then I came with this solution that I don't even know the time complexity.</p>
  
  <pre class="lang-js prettyprint-override"><code>function sumOfTwo(arr, target) {
    const complements = [];
  
    for (let [idx, val] of arr.entries()) {
      if (complements.reduce((acc, v) =&gt; (acc || v.value === val), false)) {
        return [complements.find(v =&gt; v.value === target - val).index, idx];
      }
  
      complements.push({index: idx, value: target - val});
    }
  
    return [];
  }
  </code></pre>
  
  <p>I know that I am using a for-loop but I don't know the complexity of the build-in high order functions <code>.reduce()</code> and <code>.find()</code>. I tried a couple of searches but I couldn't find anything. </p>
  
  <p>If anyone can help me would be great! Please include Big-O notation if possible.</p>
  
  <p><strong>Repl.it</strong>: <a href="https://repl.it/@abranhe/sumOfTwo" rel="noreferrer">https://repl.it/@abranhe/sumOfTwo</a></p>
  
  <hr>
  
  <p>Please also include the time complexity of the last solution.</p>