Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  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));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement