SHARE
TWEET

Untitled

a guest Sep 20th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const input = [4, 7, 1 , -3, 2];
  2. const sum = -1;
  3.  
  4. function doesPairExist(arr, sum) {
  5.     let pair = new Set();
  6.     for(let i = 0 ; i < arr.length; i++){
  7.         let value = arr[i];
  8.         if(pair.has(value)){
  9.             return true;
  10.         }
  11.         pair.add(sum - value);
  12.     }
  13.     return false;
  14. }
  15.  
  16. console.log(doesPairExist(input, sum));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top