Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const input = [4, 7, 1 , -3, 2];
- const sum = -1;
- function doesPairExist(arr, sum) {
- let pair = new Set();
- for(let i = 0 ; i < arr.length; i++){
- let value = arr[i];
- if(pair.has(value)){
- return true;
- }
- pair.add(sum - value);
- }
- return false;
- }
- console.log(doesPairExist(input, sum));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement