gg vs gg2

Edit on GitHub

Setup

Tests

  • gg

    function hasPair(arr, sum){
       var comp = [];
       for(let i=0;i<arr.length;i++) {
          if (comp.indexOf(arr[i]) !== -1) {
            console.log('ahak');
            return true;
          }
          comp.push(sum - arr[i])
       }
       return false;
    }
  • gg2

    function hasPair(arr, sum){
       var comp = [];
       for(let i=0;i<arr.length;i++) {
          if (arr[i] !== sum/2) continue;
          if (comp.indexOf(arr[i]) !== -1) {
            console.log('ahak');
            return true;
          }
          comp.push(sum - arr[i])
       }
       return false;
    }