JSFiddle - React, Tailwind, and code Playground
by hamix
JavaScript
let arr1 = [1, 2, 3, 9];
let arr2 = [1, 2, 4, 4];
//[{key:"1",value:"q"},{key:"1",value:"q"}]
function find(arr, sum) {
let aset = new Set();
let isFound = false;
arr.forEach(function(c) {
if (aset.has(c)) {
isFound = true;
return;
}
aset.add(sum - c);
// console.log(sum - c);
});
return isFound;
}
console.log(find(arr1, 15));